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?
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: http://asm.sourceforge.net/intro/Assembly-Intro.html
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:
http://www.nasm.us/doc/nasmdoc2.html#section-2.1
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:
http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html
I hope this is what you were asking...
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
.data
.globl hello
hello:
.string "Hello, world!"
.text
.global main
main:
pushq %rbp
movq %rsp, %rbp
movq $hello, %rdi
call puts
movq $0, %rax
leave
ret
EOF
$ 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;
}
EOF
$ gcc -S hello.c -o hello.s
There is also FASM for Linux.
format ELF executable
segment readable executable
start:
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
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.