不确定为什么我不能在地址计算中使用eax ...以下返回无效的操作数类型错误...
我有一个带一个参数的宏:
%macro IdPrompt 1 ; 1% - the offset within Buff at which to write the ID that is read in
mov eax, 3 ; Specify sys_read call
mov ebx, 0 ; Specify File Descriptor 0: Stdin
mov ecx, Buff+([%1]*2) ; Pass offset of the buffer to read ID into, 2 is the scale
mov edx, 3 ; Pass number of bytes to read at one pass
int 80h ; call sys_read to fill the buffer
%endmacro
宏在另一个宏中调用:
IdPrompt eax ; call IdPrompt to get one ID
我尝试使用较小的寄存器,以及缓冲区地址为:Buff +%1 * 2没有运气
答案 0 :(得分:1)
根据@ user786653的评论:
正确的语法是:
%macro IdPrompt 1 ; 1% - the offset within Buff at which to write the ID that is read in
mov eax, 3 ; Specify sys_read call
mov ebx, 0 ; Specify File Descriptor 0: Stdin
lea ecx, [Buff+%1*2] ; Pass offset of the buffer to read ID into, 2 is the scale
mov edx, 3 ; Pass number of bytes to read at one pass
int 80h ; call sys_read to fill the buffer
%endmacro
请注意lea
永远不会访问内存;它只涉及计算
因此,即使参数位于[]
方括号中,您也使用了文字寄存器值。
%1
被寄存器引用取代。在您的示例中:lea ecx,[eax*2+Buff]