Why can't I directly move a byte from memory to a 64-bit register in Intel x86-64 assembly?
For instance, this code:
extern printf
global main
segment .text
main:
enter 2, 0
mov byte [rbp - 1], 'A'
mov byte [rbp - 2], 'B'
mov r12, [rbp - 1]
mov r13, [rbp - 2]
xor rax, rax
mov rdi, Format
mov rsi, r12
mov rdx, r13
call printf
leave
ret
segment .data
Format: db "%d %d", 10, 0
prints:
65 16706
I need to change the move byte to registers r12 and r13 to this in order to make the code work properly:
xor rax, rax
mov al, byte [rbp - 1]
mov r12, rax
xor rax, rax
mov al, byte [rbp - 2]
mov r13, rax
Now, it prints what is intended:
65 66
Why do we need to do this?
Is there a simpler way of doing this?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…