changing global variables in NASM assembly

百般思念 提交于 2019-12-25 03:03:16

问题


I've defined these global variables but I cant seem to change their value in the code. I need other C modules to have access to these variables.

global base 
global freep 

SECTION .data  
  base:   dd   0           
  freep:     dd    0 

The code below gives this error:

:173: error: invalid combination of opcode and operands

So my question is how to a mov values into global variables?

  mov freep, esi

回答1:


From the NASM manual:

2.2.2 NASM Requires Square Brackets For Memory References
The rule is simply that any access to the contents of a memory location requires square brackets around the address, and any access to the address of a variable doesn't.

So if you want to store the value of esi at freep you should write:

mov [freep], esi

And if you wanted to get freep's address and put it in esi you would've written:

mov esi, freep

The instruction mov freep, esi is invalid, because freep here is an immediate (the address of freep), and you can't have an immediate as a destination operand.



来源:https://stackoverflow.com/questions/33341898/changing-global-variables-in-nasm-assembly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!