The process of getting argc
looks ok to me (for a 32-bit Linux machine), although you're 4 bytes off since the top of the stack most likely contains the return address to the startup code that called main
.
Also, the sys_write
system call expects a pointer to a string in ecx
. What you're giving it is a pointer to an integer, which isn't the same thing.
If you want to print the value of argc
you'll have to convert it to a string first (or use the printf
function).
Here's some example code (I'm using the GNU assembler since I don't have NASM on this machine):
format: .asciz "%d\n"
.text
.globl main
.type main, @function
main:
pushl 4(%esp) # push argc
pushl $format # push the format string
call printf
addl $8,%esp # pop the arguments
movl $0, %eax # return value
ret