I picked up the book "Practical reverse engineering" and i have the following example on page 14 (x86 assembly):
mov eax, 0AAAAAAAh
mov ebx, 0BBBBBBBh
push eax
push ebx
pop esi
pop edi
Now, I push eax and ebx on to the stack, but i pop esi and edi of the stack. Why is that? I thought I would push and pop the same registers.
movthat is more bytes. - Jesterpush/pop/call/retare quite similar to ordinary memory storing/loading, except those instructions use implicitlyespvalue as "top of stack pointer", so it's very natural to use them for "LIFO" (last in, first out) type of queue. But you should be able to recognize the simple memory manipulation behind it (although more atomic than if you would try to replicate it by something likesub esp,4mov [esp],eaxinstead ofpush eax) - Ped7gpush rbx / pop rdi(1 + 1 bytes) vs.mov rdi, rbx(3 bytes: REX + opcode + modrm). In 32-bit code, copying a register withmov esi,ebxstill only 2 bytes. Perhaps you're thinking of setting a register to a small immediate constant, likepush 1/pop eax(2 + 1 bytes) vs.mov eax, 1(5 bytes because there's no mov r/m32, sign_extended_imm8 encoding available). - Peter Cordes