If we consider two registers ax and bx, how do we swap their contents in Intel IA-32 just by using push and pop? I'm not allowed to use xchg.
This is not question for a homework, I'm revising for an exam.
If we consider two registers ax and bx, how do we swap their contents in Intel IA-32 just by using push and pop? I'm not allowed to use xchg.
This is not question for a homework, I'm revising for an exam.
You can either push once and use a mov instruction, or push twice. First one goes like:
push ax
mov ax, bx
pop bx
If you want to push twice, it is (as answered by others):
push ax
push bx
pop ax
pop bx
Should be standard use of a stack. Push A, Push B, Pop to A, Pop to B.
This works for IA-32 because its pop doesn't just pop the stack, it also delivers the value it pops. This is not always the case. The Standard Template Library for C++ has a pop that just manipulates the stack and you need a different command to access the top of the stack