Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this simple piece of code?

Tags:

assembly

I have the following piece of code, which should at the breakpoint show 123 at eax and 321 at ecx. For some reason that is not happening. Anyone cares to explain why?

    push ebp;
    mov ebp, esp;
    sub esp, 8;
    mov [ebp-4], 123;
    mov [ebp-8], 321;
    mov eax, [ebp-4];
    mov ecx, [ebp-8];
    pop ebp; <------------- breakpoint here
    retn;

I guess what must be wrong is that I cannot do

mov [ebp-4], 123

?

Everything else seems fine to me.

Thanks

edit: The values are: eax 1505915; ecx 1720129;

like image 269
devoured elysium Avatar asked Jan 23 '23 05:01

devoured elysium


1 Answers

You're storing byte values into memory.

Change to

mov dword ptr [ebp - 4], 123
mov dword ptr [ebp - 8], 321

eax = 1505915 is 0x16FA7B. The last byte is 7B in hex, which is 123 in decimal. ecx = 1720129 is 0x1A3F41. 41 in hex is the last byte of 321 (141).

like image 108
Michael Avatar answered Jan 29 '23 13:01

Michael