Why are you screwing up Assembly?

Asked

Viewed 129 times

1

I’m trying to learn Assembly. By compiling the following code in FASM it gives the error illegal Instruction down below Section . date.

When removing this chunk and trying to reassemble, from the same error, only now on Section . text and then on global _start.

After taking everything it mounts, but only generates a file .bin 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 any progress because I’ve already used the NASM and I’ve also had difficulties. My machine is 64 bits, but if an x64 machine can run x86 programs, that shouldn’t be a problem.

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

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

  • 1

    Technically it’s not a compiler, it’s an assembler. It’s a gaffe.

1 answer

1


In your code there are some mistakes:

  1. Was not defined the executable format, if it’s a program console, use format PE console (for x64, use PE64 instead of PE).
  2. The point of program entry, to define use the directive entry.
  3. In the definition of the sections, there are syntax errors, to specify a section you must put them inside quotation marks '.

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

    It worked. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.