Why is the assembly assembler making a mistake?

1

I'm trying to learn Assembly. When compiling the following code in FASM it gives the illegal instruction error below section .data .

When you remove this snippet and try to mount again, it gives the same error, only now in the section .text and then in the global

After getting it all it assembles, but only generates a .bin file without an executable.

section .data
    msg     db      'Olá Mundo', 0AH
    len     equ     $-msg

    section .text
    global  _start
    _start: mov     edx, len
            mov     ecx, msg
            mov     ebx, 1
            mov     eax, 4
            int     80h

            mov     ebx, 0
            mov     eax, 1
            int     80h

I'm not making progress because I've already used the NASM and I've also had difficulties. My machine is 64-bit, but if an x64 machine can run x86 programs, this should be no problem.

Even using MASM in Windows XP 32 bit has not yet accepted the programs I tried to compile (Most programs ready).

It seems like every compiler works with specific rules. Can anyone explain to me how I should proceed?

    
asked by anonymous 25.05.2015 / 05:40

1 answer

1

In your code there are some errors:

  • The executable format has not been set, if it is a console program >, use format PE console (for x64 , use PE64 instead of PE ).
  • The program entry point has not been set, to set use the entry directive.
  • In the definition of the sections, there are syntax errors, to specify a section you should put them within ' .
  • The code with these modifications should look like this:

    format PE64 console
    entry inicio
    
    section '.data'
        msg     db      'Olá Mundo', 0AH
        len     equ     $-msg
    
        section '.text'
        inicio: mov     edx, len
                mov     ecx, msg
                mov     ebx, 1
                mov     eax, 4
                int     80h
    
                mov     ebx, 0
                mov     eax, 1
                int     80h 
    
        
    25.05.2015 / 06:59