0
votes

I'm reading a book on how to write assembly for x86 Linux.

I want to assemble the following assembly source code (exit.s) on my x86_x64 Linux OS:

.section .data

.section .text
.globl _start
_start:
    mov1 $1, %eax
    mov1 $0, %ebx
    int $0x80

By calling this command: as exit.s -o exit.o

However, the assembler exits with the following error:

exit.s: Assembler messages:
exit.s: Warning: end of file not at end of a line; newline inserted
exit.s:6: Error: no such instruction: `mov1 $1,%eax'
exit.s:7: Error: no such instruction: `mov1 $0,%ebx'

From what I can gather, the instruction set for x86_x64 Linux is different from x86, hence the error. By replacing mov1 with mov, the assembler succeeds in compiling. However, seeing as the rest of the book is written for x86, I would like to be able to assemble x86 assembly for my OS.

I read somewhere that it's possible to do so by specifying the option --32, like so: as --32 exit.s -o exit.o, but by doing that, I receive the same error as before.

How do I assemble x86 source code on an x86_x64 architecture?

1
mov1 is not valid even for correct 32-bit x86 assembly. You probably want movl (last character is an L). But that does not solve your question, to use the int 80h API you do want to compile into a 32-bit application.ecm
Try the gcc commands given in stackoverflow.com/questions/36861903/…ecm
Thanks. Yeah, I mistook the l for a 1. Using the gcc compiler worked.Mike Hawkins
By the way, as that answer lists: "Use -v to have gcc show you the commands it runs to assemble and link."ecm

1 Answers

2
votes

There are two issues with this code:

 mov1 $0, %ebx

It should be movl, (See the difference between 1 and l, in some fonts they are the same.)

The other, a minor one is the missing newline, simply insert one at the end of the file.

To assemble the file use as --32 exit.s -o exit.o (Assuming a 64-bit assembler)