0

I have been trying to learn x86 Assembly on Linux and this is my code:

.386
.model flat
.code
start PROC
    mov eax, 100
    add eax, 200

    ret
start endp
end start

whenever I try to compile it with nasm, like this:

nasm -f elf32 -o <filename>.o <filename>.asm
ld -m elf_i386 -o <filename> <filename>.o

I get this error:

simple.asm:1: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
simple.asm:1: error: attempt to define a local label before any non-local labels
simple.asm:2: error: attempt to define a local label before any non-local labels
simple.asm:2: error: parser: instruction expected
simple.asm:3: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
simple.asm:3: error: attempt to define a local label before any non-local labels
simple.asm:4: error: parser: instruction expected
simple.asm:9: error: symbol `start' redefined
simple.asm:9: error: parser: instruction expected
simple.asm:10: error: parser: instruction expected

Why do I get that error? is it the compiler or the code? and how to fix it?

Reaper
  • 1
  • 2
  • 3
    That is for `masm` not `nasm`. If you have more code like this, use `masm`. Otherwise, translate to `nasm` syntax. PS: you can't `ret` from a raw entry point in linux (I assume linux due to the `elf_i386`). – Jester Dec 13 '19 at 00:47
  • This is MASM code. And to assemble your code on Linux, you can use [JWasm](https://github.com/JWasm/JWasm), a free MASM compatible assembler. But remember that the code for Windows and Linux is different - although it can be assembled with the same program. – zx485 Dec 13 '19 at 01:24

0 Answers0