Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I move the VALUE in a register to a memory variable in NASM?

Tags:

x86

assembly

nasm

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

like image 361
qscott86 Avatar asked Oct 16 '25 20:10

qscott86


1 Answers

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.

like image 161
paxdiablo Avatar answered Oct 18 '25 14:10

paxdiablo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!