I'm fairly new to linux(ubuntu 10.04) and a total novice to assembler. I was following some tutorials and I couldn't find anything specific to linux. So, my question is, what is a good package to compile/run assembler and what are the command line commands to compile/run for that package?

+2  A: 

The assembler(GNU) is as(1)

+8  A: 

The GNU assembler (gas) and NASM are both good choices. However, they have some differences, the big one being the order you put operations and their operands.

gas uses AT&T syntax:

mnemonic    source, destination

nasm uses intel style:

mnemonic    destination, source

Either one will probably do what you need.

Try out this tutorial:

Thanks, that tutorial is great since it's linux specific. Also, the tutorial had very specific instructions on how to compile and run assembler progs in linux
Rafe Kettler
gas has supported ".intel_syntax" for a while - I'd personally still use fasm, yasm or nasm though.
+2  A: 

If you are using NASM, the command-line is just

nasm file.asm -o outfile

where 'file.asm' is your assembly file (code) and 'outfile' is the executable you want.

Here is some more info:

You can install NASM in Ubuntu with the following command:

apt-get install nasm

Here is a basic Hello World in Linux assembly to wet your appetite:

I hope this is what you were asking...

+1  A: 

The GNU assembler is probably already installed on your system. Try man as to see full usage information. You can use as to compile individual files and ld to link if you really, really want to.

However, GCC makes a great front-end. It can assemble .s files for you. For example:

$ cat >hello.s <<EOF
.globl hello
.string "Hello, world!"

.global main
    pushq   %rbp
    movq    %rsp,       %rbp
    movq    $hello,     %rdi
    call    puts
    movq    $0,         %rax
$ gcc hello.s -o hello
$ ./hello
Hello, world!

The code above is AMD64. It would be different if you're still on a 32-bit machine.

You can also compile C/C++ code directly to assembly if you're curious how something works:

$ cat >hello.c <<EOF
#include <stdio.h>
int main(void) {
    printf("Hello, world!\n");
    return 0;
$ gcc -S hello.c -o hello.s
Jay Conrod
+1  A: 

There is also FASM for Linux.

format ELF executable

segment readable executable

mov eax, 4
mov ebx, 1
mov ecx, hello_msg
mov edx, hello_size
int 80h

mov eax, 1
mov ebx, 0
int 80h

segment readable writeable

hello_msg db "Hello World!",10,0
hello_size = $-hello_msg

It comiles with

fasm hello.asm hello
Artur Artamonov

My suggestion would be to get the book Programming From Ground Up:

That is a very good starting point for getting into assembler programming under linux and it explains a lot of the basics you need to understand to get started.


3 syntax (nasm, tasm, gas ) in 1 assembler, yasm.