0

不知道为什么我不能在地址计算中使用 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

宏在另一个宏中被 this 调用:

    IdPrompt eax            ; call IdPrompt to get one ID

我尝试使用较小的寄存器,以及缓冲区地址为: Buff+%1*2 没有运气

4

1 回答 1

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]

于 2013-10-16T01:24:26.607 回答