asm中的内存寻址
我正在学习汇编,这是我的(许多)问题之一: 我想更改数组的某些索引的值。 假设:
- %eax 包含我的新值
- 堆栈顶部(即 (0)%esp)包含数组的索引
- -4(%ebp) 包含数组的地址。
我尝试过 movl %eax, (-4(%ebp),0(%esp),4) ,但没有成功。 更糟糕的是,它会引发语法错误: bobi.s:15: Error: junk `(%ebp),0(%esp),4)' after expression
正确的语法是什么?
I'm learning asm and here's one of my (many) problems:
I'd like to change the value of some index of an array.
Let's say that:
- %eax contains my new value
- the top of the stack (ie (0)%esp) contains the index of the array
- -4(%ebp) contains the adress of the array.
I've tried movl %eax, (-4(%ebp),0(%esp),4)
but it did not work.
Worse, it throws a syntax error : bobi.s:15: Error: junk `(%ebp),0(%esp),4)' after expression
What is the correct syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 x86 汇编中没有单一指令可以执行此操作。你必须找到一个可用的寄存器,用它来存储从
-4(%ebp)
获得的数组的地址,找到另一个寄存器来保存索引0(%esp)
,只有这样才可以访问您感兴趣的单元(并且在更多类似 RISC 的程序集中,您仍然需要将这两个寄存器添加在一起,然后才能进行内存访问)。假设寄存器可用,类似:
应该可以工作。
There is no single instruction to do this in x86 assembly. You have to find an available register, use it to store the address of the array that you get from
-4(%ebp)
, find another register to hold the index0(%esp)
, and only then does it become possible to access the cell you are interested in (and in more RISC-like assemblies, you'd still need to add these two registers together before you can do the memory access).Assuming the registers are available, something like:
should work.