1
.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

the code is for switching first char in the second one in the string, error A2070 "invalid instruction operands" on the line "mov byte ptr [ebx + ecx], GlobSecC"

any suggestions to fix / better way to go through String in masm 32?

fuz
  • 88,405
  • 25
  • 200
  • 352

1 Answers1

1

You cannot have two memory operands in an x86 instruction (except for certain special purpose instructions). To fix the code, first load GlobSecC into a register, then store that register into [ebx + ecx].

movzx edx, GlobSecC
mov [ebx + ecx], dl
fuz
  • 88,405
  • 25
  • 200
  • 352