Problems in moving a register value to a memory address in assembly language using fasm assembler?

11.7k views Asked by At

I am really confused about this one thing. I was following the book assembly programming for x86 processors and i was reading about the mov instructions and how it works. So, the author said that the following instruction is valid mov mem,reg.....basically moving a register value to a memory address.

Now this what i tried and i keep getting this error called invalid operand. Can someone please explain me what exactly is the error.

#fasm#

 mov ax,[var] ;the value 67 is moved to the ax register works perfect
 mov myvar,ax ; my aim is to move the value 67 to the memory location of ;myvar but then i keep getting this error - Invalid operand? why is that?

var: dw 67   
myvar: dw ?
1

There are 1 answers

5
fjardon On

Can you try this:

mov [myvar], ax
  • myvar is a constant holding the address of the memory allocated for the variable.
  • [myvar] instructs to fetch/store a value in memory at the address pointed by myvar

So:

mov ax, myvar  ; load the address of myvar in ax
mov ax, [myvar]; load the value stored at address myvar
mov [myvar], ax; store the value of ax at address myvar