section .data VAL_A dw 111 VAL_B dw 222 message db "The values were swapped.", 10 message_len equ $ - message section .text global _start _start: ; Five valid MOV forms: ; 1. Immediate to register ; 2. Immediate to memory ; 3. Register to register ; 4. Register to memory ; 5. Memory to register ; Memory-to-memory MOV is invalid and must be avoided. lea rbx, [rel VAL_A] ; RBX holds the address of VAL_A lea rsi, [rel VAL_B] ; RSI holds the address of VAL_B ; Swap the word values using a temporary register. mov ax, [rbx] ; Load VAL_A into AX mov dx, [rsi] ; Load VAL_B into DX mov [rbx], dx ; Store old VAL_B into VAL_A mov [rsi], ax ; Store old VAL_A into VAL_B ; Display the confirmation message. mov eax, 1 ; sys_write mov edi, 1 ; standard output lea rsi, [rel message] mov edx, message_len syscall ; Exit cleanly. mov eax, 60 ; sys_exit xor edi, edi ; exit status 0 syscall
To embed this project on your website, copy the following code and paste it into your website's HTML: