XCHG Instruction
XCHG — Exchange |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allows to exchange two operands without needing a third register or variable to hold a temporary value. The rules for operands in the are the same as those for the instruction. |
|
| Exchanging X and X+2 (?) | ||
xchg ax, X
|
xchg ax, [ebx+2]
|
xchg ax,[ebx]
|
INCLUDE Irvine32.inc .data X DWORD 12345678h .code main PROC mov eax, X xchg ax, X mov X+2, ax mov eax, X call WriteHex exit main ENDP END main |
INCLUDE Irvine32.inc
.data
X DWORD 12345678h
.code
main PROC
mov eax, X
mov ebx, OFFSET X
xchg ax, [ebx+2]
xchg [ebx], ax
mov eax, X
call WriteHex
exit
main ENDP
END main
|
INCLUDE Irvine32.inc .data X DWORD 12345678h .code main PROC mov eax, X mov ebx, OFFSET X xchg ax, [ebx] xchg [ebx+2], ax mov eax, X call WriteHex exit main ENDP END main |
| Output | Output | Output |
|
I’ll call you later. Don’t call me later. Call me Dad! |