我是装配编程的新手(x86 asm with MASM),并且正在学习 ESI 寄存器支持的间接,你只需要将地址放入 ESI 然后使用间接运算符,您将能够访问指向的数据。
Q1.在编码中,可以使用 [esi + 4] ,但不能使用 esi + 4 (结果出错)。为什么?因为在汇编中,间接运算符([])显然不是必需的,主要是为了程序员的理解。
Q2。如果我将间接应用于指针变量,那么它们似乎不起作用。为什么?指针只是用作容器。
Eg-
mov eax, [esi] ; It sets eax with the value of memory location pointed by esi
mov eax,[ptr4] ; Does not work the same
答案 0 :(得分:5)
这是MASM语法的一个怪癖。 [
... ]
会自动插入内存地址标签周围。换句话说
mov eax, [ptr4]
表示"将地址ptr4
的4个字节加载到eax
寄存器中。"但是ptr4
是内存地址的标签,所以即使你忘了使用方括号并写
mov eax, ptr4
MASM将自动插入括号。两条线的含义相同:"将地址ptr4
的4个字节加载到eax
寄存器中。"
MASM不会对寄存器参数执行此自动插入,但是:
mov eax, esi ; copy the esi register to the eax register
mov eax, [esi] ; load 4 bytes at the address esi into the eax register
这只是MASM的一个怪癖,你必须习惯。