A section from the ASM guide I'm reading:
"MOV AX,51h
MOV BX,4Fh
XCHG AX,BX
PUSH AX
MOV AX,34h
POP BX
PUSH BX
POP AX
First AX is equal to 51h and BX to 4Fh, than the 2 get exchanged. Now we got
AX = 4Fh and BX = 51h. AX gets pushed on the stack, then set to 34h:
AX = 34h and BX = 51h. BX gets poped, than pushed:
AX = 34h and BX = 4Fh. Finally AX gets poped. So the final result is:
AX = 4Fh and BX = 4Fh"
Can someone please explain why AX= 4Fh and not 34h?? That's the last value that was copied to it.
Sorry I haven't posted on /prog/ much and wasn't sure if [code] was supported. Hopefully the text is still readable/good enough for your eyes, your highness.
>>3
Don't listen to >>2. >>2
Here's the [code]ified version:
MOV AX,51h
MOV BX,4Fh
XCHG AX,BX
PUSH AX
MOV AX,34h
POP BX
PUSH BX
POP AX
First AX is equal to 51h and BX to 4Fh, than the 2 get exchanged. Now we got AX = 4Fh and BX = 51h. AX gets pushed on the stack, then set to 34h: AX = 34h and BX = 51h. BX gets poped, than pushed: AX = 34h and BX = 4Fh. Finally AX gets poped. So the final result is: AX = 4Fh and BX = 4Fh
Name:
Anonymous2011-03-09 1:55
The PUSH instruction stores its operand on the stack.
The POP instruction retrieves the most recent pushed value.
POP stuff is just: mov stuff,[(e)sp]
add (e)sp,{size of popped object}
Or just take whatever is at the top of the stack and place it in the argument passed to pop then add the stack pointer by the size of popped object (usually 2-4 bytes depending on CPU mode, see Intel CPU documentation for details).