* Re: I need little help..
2004-03-26 4:02 I need little help RaZoR
@ 2004-03-26 0:23 ` Brian Raiter
2004-03-26 0:54 ` Robert G. Plantz
0 siblings, 1 reply; 3+ messages in thread
From: Brian Raiter @ 2004-03-26 0:23 UTC (permalink / raw)
To: linux-assembly
> Hi again.. I wanted to ask you how to write (in gas style) program
> which gets the user id (using syscall 24) and then printing it to
> the screen (NOT using the printf function , but using syscall 4)...
If you refuse to use printf, then you'll need to translate the number
into the ASCII decimal representation yourself. (I assume that if you
can't use printf(), then sprintf() is also off-limits.)
Once you've done that, you can just output the string directly.
; itoa:
; When called, the number to transform is in eax, and a
; pointer to the buffer to receive the string is in edi.
; Upon return, itoa leaves the length of the string in eax.
mov eax, number
mov edi, buffer
call itoa
; now display the string using the write syscall.
mov edx, eax
mov ecx, buffer
mov ebx, FILENO_STDOUT
mov eax, 4
int 0x80
If you don't want to use sprintf(), then you should really try to
write itoa yourself. It's a classic job-interview question, and one
that every hacker ought to try to write themselves.
b
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: I need little help..
2004-03-26 0:23 ` Brian Raiter
@ 2004-03-26 0:54 ` Robert G. Plantz
0 siblings, 0 replies; 3+ messages in thread
From: Robert G. Plantz @ 2004-03-26 0:54 UTC (permalink / raw)
To: Assembly Linux
Uh, I think the poster asked for "in gas style."
Assuming that number and buffer are in the .data segment:
.data
number: .int 123
buffer: .space 50
and the existence of itoa as described by Brian Raiter, I got:
movl number, %eax
movl $buffer, %edi
call itoa
movl %eax, %edx
movl $buffer, %ecx
movl $1, %ebx
movl $4, %eax
int $0x80
to do the job.
Bob
On Mar 25, 2004, at 4:23 PM, Brian Raiter wrote:
>> Hi again.. I wanted to ask you how to write (in gas style) program
>> which gets the user id (using syscall 24) and then printing it to
>> the screen (NOT using the printf function , but using syscall 4)...
>
> If you refuse to use printf, then you'll need to translate the number
> into the ASCII decimal representation yourself. (I assume that if you
> can't use printf(), then sprintf() is also off-limits.)
>
> Once you've done that, you can just output the string directly.
>
> ; itoa:
> ; When called, the number to transform is in eax, and a
> ; pointer to the buffer to receive the string is in edi.
> ; Upon return, itoa leaves the length of the string in eax.
>
> mov eax, number
> mov edi, buffer
> call itoa
>
> ; now display the string using the write syscall.
>
> mov edx, eax
> mov ecx, buffer
> mov ebx, FILENO_STDOUT
> mov eax, 4
> int 0x80
>
> If you don't want to use sprintf(), then you should really try to
> write itoa yourself. It's a classic job-interview question, and one
> that every hacker ought to try to write themselves.
>
> b
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-assembly" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
------------------------------------------------------------------------
---------------
practice (v): To do or perform repeatedly in order to acquire skill.
------------------------------------------------------------------------
---------------
Robert G. Plantz, PhD | http://www.cs.sonoma.edu/~bob
Sonoma State University | ph: (707) 664-2806
CS Department | fax: (707) 664-3012
1801 E. Cotati Avenue | email: plantz@sonoma.edu
Rohnert Park, CA 94928
^ permalink raw reply [flat|nested] 3+ messages in thread
* I need little help..
@ 2004-03-26 4:02 RaZoR
2004-03-26 0:23 ` Brian Raiter
0 siblings, 1 reply; 3+ messages in thread
From: RaZoR @ 2004-03-26 4:02 UTC (permalink / raw)
To: linux-assembly
Hi again.. I wanted to ask you how to write (in gas style)
program which gets the user id (using syscall 24) and then printing it to
the screen (NOT using the printf function , but using syscall 4)...
If you could give me an example?
Thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-03-26 4:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-26 4:02 I need little help RaZoR
2004-03-26 0:23 ` Brian Raiter
2004-03-26 0:54 ` Robert G. Plantz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox