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


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?



Relevant Pages

  • Re: atoi return
    ... The function that allows you to specify the file handle is fgets(), ... best, problematic, since stdout is defined as an output stream. ...
    (comp.lang.c)
  • Re: Which PHP am I running?
    ... a command line switch to be set to specify the mode. ... GUI apps on Windows have null stdout. ...
    (comp.lang.php)
  • Re: atoi return
    ... The function that allows you to specify the file handle is fgets(), not gets, and it is possible to use it safely, because it also takes an length argument for the buffer. ... However, using it on stdout seems, at best, problematic, since stdout is defined as an output stream. ... I suspect that you mean something substantially different from what you wrote. ...
    (comp.lang.c)
  • Re: Which PHP am I running?
    ... a command line switch to be set to specify the mode. ... GUI apps on Windows have null stdout. ...
    (comp.lang.php)