x86-64 Cheat sheet

 

0x1122334455667788
  ================  rax (64 bits)
          ========  eax (32 bits)
              ====  ax  (16 bits)
              ==    ah   (8 bits)
                ==  al  (8 bits)

mov eax, 0x11112222 ; eax = 0x11112222
mov ax,  0x3333     ; eax = 0x11113333 (low 16 bits changed)
mov al,  0x44       ; eax = 0x11113344 (low 8 bits changed)
mov ah,  0x55       ; eax = 0x11115544 (high 8 bits changed)
xor ah,  ah         ; eax = 0x11110044 (high 8 bits cleared)
mov eax, 0x11112222 ; eax = 0x11112222
xor al,  al         ; eax = 0x11112200 (low 8 bits cleared)
mov eax, 0x11112222 ; eax = 0x11112222
xor ax, ax          ; eax = 0x11110000 (low 16 bits cleared)

mov rax, 0x1111222233334444 ; rax = 0x1111222233334444
mov eax, 0x55556666         ; actual: rax = 0x0000000055556666
                            ; expected: rax = 0x1111222255556666
                            ; upper 32 bits seem to be lost!
mov rax, 0x1111222233334444 ; rax = 0x1111222233334444
mov ax, 0x7777              ; rax = 0x1111222233337777 (works!)
mov rax, 0x1111222233334444 ; rax = 0x1111222233334444
xor eax, eax                ; actual: rax = 0x0000000000000000
                            ; expected: rax = 0x1111222200000000
                          

 

MOV   register, register
MOV   register, immediate
MOV   memory,   immediate
MOV   register, memory
MOV   memory,   register

MOV DEST, SRC;          copy SRC into DEST
MOV DEST, [SRC];      cope value at memory address SRC into DEST

 

 

mov eax, var == lea eax, [var] ; i.e. mov r32, imm32
lea eax, [var+16] == mov eax, var+16
lea eax, [eax*4] == shl eax, 2 ; but without setting flags