I'm trying to move the associated VALUE (not memory address) contained in a register to a memory variable, but it is not working.
section .data
regValue dq 0
section .text
global main
main:
push rbp
mov rbp, rsp
mov rax, 844
mov rdi, 9393
mov [regValue], [rdi]
I get error: error: operation size not specified
Well, for a start, the value of rdi is actually rdi rather than [rdi]. The latter, even assuming it's valid (I'm more of a gas man than a nasm man), would be the value stored in the memory that rdi points to.
And, to specify sizes of operands (where gas uses the more succinct movl/movb/etc operations), you specify the size with the operands, such as:
mov qword [regValue], 9393
However, I don't think that's necessary when you're using a 64-bit register like rdi for the source since the size can be inferred from that. I think you can just do:
mov [regValue], rdi
BTW, in NASM you should use default rel at the top of your file to prefer RIP-relative addressing modes for static data (like [regValue]), instead of 32-bit absolute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With