Code: Select all
Instructions using ModR/M byte (between registers) are very useful. This is the way to clear registers and moving values. Of course, we are restricted to use only lowest 16 bits.
16-bit 32-bit 64-bit
MOV AX, BX MOV EAX, EBX MOV EAX, EBX
XOR AX, AX XOR EAX, EAX XOR EAX, EAX
Immediate values need to be 8-bit. This makes code a little bit longer.
16-bit 32-bit 64-bit
MOV AL, 8 MOV AL, 8 MOV AL, 8
MOV AH, 8 MOV AH, 8 MOV AH, 8
To access a memory location, we could use "BX == EDI == RDI". It means that the memory location should have two bytes (actual value) and two zero bytes if using AX/EAX.
16-bit 32-bit 64-bit
MOV [BX], AX MOV [EDI], EAX MOV [RDI], EAX
MOV AX, [BX] MOV EAX, [EDI] MOV EAX, [RDI]
Relative calls can not be used so we must use indirect addresses.
16-bit 32-bit 64-bit
CALL AX CALL EAX CALL RAX
RET RET RET
Short jumps and indirect jumps can be used.
16-bit 32-bit 64-bit
JMP rel8 JMP rel8 JMP rel8
JMP AX JMP EAX JMP RAX
Short conditional jumps can be used.
16-bit 32-bit 64-bit
JC rel8 JC rel8 JC rel8