简体   繁体   中英

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

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM