Question

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;

Was it helpful?

Solution

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).

OTHER TIPS

I was under the impression (and I might be wrong) that you can't push values into memory addresses like that. You have to go via registers:

MOV EAX, 123
MOV [EBP-4], EAX

As I said, I might be wrong. But give it a go. Check out the instruction set manual as well. It'll show you what operations you can do on what addressing modes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top