Star Hype News.

Premium celebrity moments with standout appeal.

general

How can I compile & run assembly in Ubuntu 18.04?

By Matthew Cannon

So recently I've wanted to learn assembly, so I learnt a bit. I put this into nano and saved it as playground.asm. Now I'm wondering, how do I compile and run it? I've already searched everywhere and still cant find it. I'm really curious and there's no point learning a language if you can't even use it.

3

2 Answers

In all currently supported versions of Ubuntu open the terminal and type:

sudo apt install as31 nasm 

as31: Intel 8031/8051 assembler
This is a fast, simple, easy to use Intel 8031/8051 assembler.

nasm: General-purpose x86 assembler
Netwide Assembler. NASM will currently output flat-form binary files, a.out, COFF and ELF Unix object files, and Microsoft 16-bit DOS and Win32 object files.

This is the code for an assembly language program that prints Hello world.

section .text
global _start
_start: mov edx,len mov ecx,msg mov ebx,1 mov eax,4 int 0x80 mov eax,1 int 0x80
section .data
msg db 'Hello world',0xa
len equ $ - msg 

If you are using NASM in Ubuntu 18.04, the commands to compile and run an .asm file named hello.asm are:

nasm -f elf64 hello.asm # assemble the program
ld -s -o hello hello.o # link the object file nasm produced into an executable file
./hello # hello is an executable file
8

Ubuntu comes with as (the portable GNU assembler)

as file.s -o file.out
ld file.out -e main -o file
./file

-o: Tells where to send the output
-e: Tells ld the start symbol

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy