0
votes

I am using NASM, x86 and it give me this error and I don't understand why

%include "io.inc"
section .data
 msg: db "hello world",0 
 msg2: db 13
 count: dw 13
section .text
extern printf
global CMAIN

CMAIN:
        push ebp
        mov ebp,esp
        mov eax,msg
        mov ebx,count
        mov esi,0
        mov edi,0
        add edi,count
        dec edi

   again:
            mov eax, msg[esi]
            mov msg2[edi],eax
            inc esi
            dec edi
            loop again

            call printf






        mov esp,ebp
        pop ebp
        ret
1
What error do you get? “it give me this error” is not an error description. What is your question? What line does the error indicate?fuz
@fuz the error is in the question title, but I got confused too at first, then the edit even added more code while those two lines were sort of enough in this particular question.Ped7g
OP: I took a quick look at the other bits of source, and it looks like MASM style, i.e. doing mov ebx,count probably expecting the ebx to load the value 13, but in NASM the memory value must be in brackets, so this will instead store memory address count into ebx, not the value from memory. Not sure which tutorial/book you use, but you will either put more effort in the beginning to not just learn x86 asm, but also to learn to recognize MASM vs NASM (small) syntax differences and fix them, or you should switch book or the assembler. All of those options sounds OK (maybe even try all!).Ped7g

1 Answers

2
votes

Because those two lines are not in NASM syntax.

The mov eax, msg[esi] is almost parsed as mov eax,msg (load eax with address of msg), but then unexpected [esi] happens instead of new line.

The mov msg2[edi],eax is hard to guess, what it is like for parser (mov immediate,eax doesn't exist), but nothing legal either.

If you want to work with memory values, put whole address calculation inside brackets, like:

        mov eax, [msg+esi]
        mov [msg2+edi], eax

See NASM documentation - 3.3 Effective Addresses for full syntax of memory operands.