Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?
From: aaron (ashy_20_at_hotmail.com)
Date: 05/25/04
- Next message: Phil Carmody: "Re: Struct / Class Performance?"
- Previous message: Robert Wessel: "Re: Struct / Class Performance?"
- Next in thread: Robert Redelmeier: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: Robert Redelmeier: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: Frank Kotler: "Re: Write arguments on stack to stdout in Linux: How do i count the"
- Reply: Charles Banas: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: Tim Roberts: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: aaron: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 25 May 2004 05:34:13 +0000 (UTC)
I have been trying to write to stdout the arguments passed to the program.
My code works fine currently except that i have to specify how many char's
to write.
How do i find out how many char's are in the argument?
I had a look at the "String and Character Translation Instructions"
section of the "Intel 80386 Reference Programmer's Manual" but i still
dont understand what these instructions do.
Here is my code:
**********************
section .text
global _start
_start:
pop ebp ;argc
pop ecx ;get program name off stack
argument:
dec ebp ;minus the last argument
pop ecx ;get argument
mov edx,5 ;argument length - This is the problem bit.
;write to stdout
mov eax,4 ;write syscall
mov ebx,1 ;to stdout
int 80h ;call kernel
;loop back to argument if there are any arguments left
cmp ebp,0 ;see if any arguments left
jne argument;get the next one if there is
;exit
mov eax,1 ;exit syscall
mov ebx,0 ;return success
int 80h ;call kernel
*********************************
I have been assembling it with nasm and linking it with ld like this:
nasm -f elf args.asm
ld -s -o args args.o
and running it with various arguments like this:
<aaron@Ashy 01:52 PM:~/coding/assembly>$ ./args hello there
hellothere<aaron@Ashy 01:52 PM:~/coding/assembly>$
How can i count the number of char's in each argument?
- Next message: Phil Carmody: "Re: Struct / Class Performance?"
- Previous message: Robert Wessel: "Re: Struct / Class Performance?"
- Next in thread: Robert Redelmeier: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: Robert Redelmeier: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: Frank Kotler: "Re: Write arguments on stack to stdout in Linux: How do i count the"
- Reply: Charles Banas: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: Tim Roberts: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Reply: aaron: "Re: Write arguments on stack to stdout in Linux: How do i count the number of char's in each argument?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|