How can I load a single byte from address? I thought it would be something like this:
mov rax, byte[rdi]
How can I load a single byte from address? I thought it would be something like this:
mov rax, byte[rdi]
mov al, [rdi]
Merge a byte into the low byte of RAX.
Or better, avoid a false dependency on the old value of RAX by zero-extending into a 32-bit register (and thus implicitly to 64 bits) with MOVZX:
movzx eax, byte [rdi] ; most efficient way to load one byte on modern x86
Or if you want sign-extension into a wider register, use MOVSX. (On some CPUs this is just as efficient as MOVZX.)
movsx eax, byte [rdi] ; sign extend to 32-bit, zero-extend to 64
movsx rax, byte [rdi] ; sign extend to 64-bit
The MASM equivalent replaces byte with byte ptr.
A mov load doesn't need a size specifier (al destination implies byte operand-size). movzx always does for a memory source because a 32-bit destination doesn't disambiguate between 8 vs. 16-bit memory sources.