0

I am trying to use this instruction movs[x] that moves an entire string. When using it on the NASM assembler, it is working well but with the MASM assembler, an error occurs.

NASM:

section .data
msg db 'Hello', 0
len equ $ - msg

section .bss
msg2 resb len

section .text
global CMAIN
CMAIN:
    mov ecx, 0
    mov ecx, len
    mov esi, msg
    mov edi, msg2
    rep movsb     
    ret

The previous code is working well.

MASM:

.386
.model flat, c
.stack 50

.data
msg db  'Hello', 0
len equ $ - msg
msg2 db len dup(0)


.code       
_start:
    mov ecx, 0
    mov ecx, len
    mov esi, msg
    mov edi, msg2
    rep movsb

    ret
end _start

The previous code always gives me Error A2022 instruction operands must be the same size and points to those lines:

mov esi, msg
mov edi, msg2

I know the msg and msg2 are 8-bit and ESI register is 32-bit but there's no 8-bit ESI, and why that code is working well on NASM?

How do I solve that problem?

Lion King
  • 32,851
  • 25
  • 81
  • 143
  • 4
    That has nothing to do with `movsb`. It has to do with how you load an address in masm. You should use `mov esi, offset msg` – Jester May 30 '21 at 12:47
  • 2
    In the future, you might not want to use the abbreviation `movsx` this way, as it can be confused with the [Move with Sign-Extension](https://www.felixcloutier.com/x86/movsx:movsxd) instructions whose mnemonic is `movsx`. – Nate Eldredge May 30 '21 at 16:44

0 Answers0