For an assignment, I have the following code:
.global _start
.section .data
arr: .short 1, 2, 3, 4, 5
b: .quad 0x1234567890123456
.section .text
_start:
movq $arr, b
We are to assume that the address of the arr label is 0xDEADBEEF, and decide if the command is legal.
Looking through the Intel manual, I found that movq takes a 32-bit number and sign-extends it into the 64-bit memory location (b in this case).
When assembling and running the code locally (using as and gdb), everything seems to work fine, but the address of arr is 0x402000, and not 0xDEADBEEF. So I tried running:
movq $0xDEADBEEF, b
but the assembly failed with:
Error: operand type mismatch for `movq'
which is confusing, as 0xDEADBEEF is 32-bit literal.
So my two questions are:
- Why does the above command not work (I assume it has something to do with the sign extension)?
- If the address of
arrwas0xDEADBEEF, would the assembler fail as well?