I have this assembly code and what I think it does is print using the printf function. i am not really familiar with C, but I created a main function and I printed out printf("%d, %d", x, y) where x and y are both zero.
I converted the C code to assembly but I got something totally different. Can somebody help me understand what the assembly code below does?
mov %edx,0x8(%esp)
mov %eax,0x4(%esp)
movl $0x80486a0,(%esp)
call 8048360 <printf@plt>
As a very literal translation of your assembly,
move the value in edx onto the stack at offset 8 (esp + 8)
move the value in eax onto the stack at offset 4 (esp + 4)
move [the 32bit value] 0x80486a0 onto the stack at offset 0
This is a very basic way that arguments to a function will be placed on the stack–RTL or C order. The value at the lowest offset is the first argument (in this case, the address of your string literal in memory), and the value at the highest offset is the last argument.
When you hit the call:
Your program will jump to the given address (which your disassembler has identified as the printf function), read the values from the stack, perform the print operation, and then return back to your code, resuming operation at the next instruction after your call.
I’m going to guess that your source looked something like this:
Depending on your OS/compiler, you might be guaranteed that eax and edx will have the value 0 at startup. Or you could be missing the initialization code from your snippet.