lundi 24 mars 2014

Why can't I move directly a byte to a 64 bit registry?


Vote count:

0




Why can't I directly move a byte from memory to a 64-bit registry 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.



asked 42 secs ago

antoyo

1,489





Aucun commentaire:

Enregistrer un commentaire