改变全局变量在NASM汇编 [英] changing global variables in NASM assembly

查看:556
本文介绍了改变全局变量在NASM汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义这些全局变量,但我似乎无法更改code自己的价值。我需要其他的C模块能够访问这些变量。

 全球基地
全球freep段.data
  基地:DD 0
  freep:DD 0

在code以下给出了这样的错误:

:173:错误:OP code和操作数的组合无效

所以我的问题是如何将MOV值到全局变量?

  MOV freep,ESI


解决方案

从的在NASM手动


  

2.2.2 NASM需要方括号内存引用结果的规则很简单,就是一个存储单元的内容有任何访问需要的地址方括号括起,并以该地址的任何访问的变量没有。


所以,如果你想的 ESI 的值存储在 freep 你应该写:

  MOV [freep],ESI

如果你想获得 freep的地址,并把它放在 ESI 你已经写了:

  MOV ESI,freep

指令 MOV freep,ESI 是无效的,因为 freep 这里是一个即时(即<$地址C $ C> freep ),你不能有立竿见影的作为目的操作数。

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

解决方案

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.

这篇关于改变全局变量在NASM汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆