使用__asm时操作数类型错误

Improper operand type error using __asm

本文关键字:类型 错误 操作数 asm 使用      更新时间:2023-10-16

操作数类型不当是什么意思?

我正在尝试将一些c++代码转换为汇编程序

     temp_char = OChar[i]         //temp_char is a character and OChar is array and i is the index

ive tried

     mov eax, i
     mov temp_char, [eax+OChar]

     mov eax, i
     movsx temp_char, [eax+OChar]

谁能解释一下如何避免不正确的操作数类型?

这是完整代码

                  char temp_char;                       
                   int i;
   __asm{       
            mov i,0
            jmp checkend
     startfor:      mov eax,i   
            add eax,1
            mov i,eax

   checkend:        cmp i,length    
            jge endloop     
            movsx   temp_char, [eax+OChars] 
            //encryption of string//
            push eax                
            and eax,0xAA            
            not al                  
            mov edx,eax             
            pop eax                 
            and eax,0x55            
            xor ecx,edx             
            xor ecx,eax             
            rol cl,2                
            sub al,0x20
                            pop ebp                             
            //end of encryption//
            movsx   [eax+EChars], temp_char 
            jmp startfor        
   endloop:     ret
}   

你不能在x86上直接把东西从内存移到内存——你必须通过寄存器——沿着下面的行:

 mov eax, i
 mov bx, word ptr [eax+OChar]
 mov temp_char, bx