assembly 为什么我在第41行得到“无效的指令操作数”?MASM 32 [duplicate]

2fjabf4q  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(168)

此问题在此处已有答案

MOVing between two memory addresses(6个答案)
Why can't MOV have both operands as memory locations? [closed](1个答案)
关闭3个月前.

.686p 
.xmm
.model flat,c
.stack  4096

; include C libraries
includelib      msvcrtd
includelib      oldnames
includelib      legacy_stdio_definitions.lib

; imported functions
extrn   printf:near

.data ; initialized global vars
IntegerFormat   db  "The result is: %d",0dh,0ah,0
GlobWord      db "This is just a test",0dh,0ah,0
GlobFstC      dd "i"
GlobSecC      db "g"

.code
        
public  main

main proc
xor     eax, eax
xor     ecx, ecx
xor     ebx, ebx
mov     ecx, -1
mov     ebx, offset GlobWord

SwitchChars:
    inc     ecx
    movsx   eax, byte ptr [ebx + ecx]
    cmp     eax, 0
    je  Exit
    cmp     eax, GlobFstC
    jne     SwitchChars
    mov     byte ptr [ebx + ecx], GlobSecC 
    jmp     SwitchChars

Exit:
    movsx   eax, GlobWord
    push    eax    
    push    offset IntegerFormat
    call    printf  ; call printf(IntegerFormat, 3)
    add     esp, 8 
    xor     eax, eax
    ret
    main endp
    end

代码用于在字符串中的第二个字符中切换第一个字符,错误A2070“mov byte ptr [ebx + ecx],GlobSecC”行上的“无效指令操作数”
有什么建议来修复/更好的方式来通过字符串在masm 32?

ttp71kqs

ttp71kqs1#

一条x86指令中不能有两个内存操作数(某些特殊用途的指令除外)。要修复此代码,请先将GlobSecC加载到寄存器,然后将该寄存器存储到[ebx + ecx]

movzx edx, GlobSecC
mov [ebx + ecx], dl

相关问题