Steffen
Steffen

Reputation: 165

IA 32 read command line argument

I am trying to read command line arguments with assembly code for IA 32. I found an explanation of how to do it here http://www.paladingrp.com/ia32.shtml. I am able to use the stack pointer to get the number of arguments but I am not able to get the value of the arguments. Here is what I am trying to do:

movl 8(%esp), %edx  # Move pointer to argument 1 to edx
movl (%edx), %ebx   # Move value of edx to ebx
movl $1, %eax       # opcode for exit system call in eax
int $0x80           # return

Am I getting the correct pointer? If so, how do I get the value of it? If not, how do I get the correct pointer?

Upvotes: 1

Views: 417

Answers (1)

Employed Russian
Employed Russian

Reputation: 213386

movl (%edx), %ebx # Move value of edx to ebx

That doesn't move value of EDX to EBX (the comment is incorrect).

That dereferences pointer in EDX, and puts the result of dereference into EBX. So if you invoked your program with ./a.out foo, then EBX will end up being 0x006f6f66 (== '\0oof' ("foo\0" in little-endian)).

I am guessing that's not what you wanted, but your question is not very clear about what you are expecting to happen where.

Upvotes: 2

Related Questions