Compile / run assembler on Linux?

I am new to Linux (Ubuntu 10.04) and new to assembler. I followed some tutorials and I could not find anything specific for Linux. So my question is: what is a good package to compile / run assembler and what command line commands to compile / run for this package?

+48
assembly x86 linux ubuntu
Jul 23 '10 at 2:11
source share
7 answers

The GNU assembler (gas) and NASM are good choices. However, they have some differences, most of which are the order in which you put the operations and their operands.

Gas

uses the AT & T syntax:

mnemonic source, destination 

nasm uses the intel style:

 mnemonic destination, source 

Maybe someone will do what you need.

Try this tutorial: http://asm.sourceforge.net/intro/Assembly-Intro.html

+40
Jul 23 2018-10-23T00:
source share

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

However, GCC makes a great interface. It can collect .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 are still on a 32-bit machine.

You can also compile C / C ++ code directly to the assembly if you are interested in 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 
+44
Jul 23 '10 at 3:44
source share

If you use NASM, the command line is just

 nasm file.asm -o outfile 

where 'file.asm' is your build 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 on Ubuntu with the following command:

 apt-get install nasm 

Here is the basic Hello World build on Linux that will help your appetite:

http://web.archive.org/web/20120822144129/http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html

Hope this is what you asked for ...

+17
Jul 23 '10 at 3:26
source share

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 

He moves with

 fasm hello.asm hello 
+8
Aug 18 2018-10-18T00:
source share

My suggestion was to get the book "Programming from scratch":

http://nongnu.askapache.com/pgubook/ProgrammingGroundUp-1-0-booksize.pdf

This is a very good starting point for assembly language programming for Linux, and it explains many of the basics you need to understand to get started.

+6
Sep 29 '10 at 13:47
source share

Assembler (GNU) as (1)

+3
Jul 23 '10 at 2:17
source share

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

http://www.tortall.net/projects/yasm/

+3
Oct 21 '10 at 10:41
source share



All Articles