⚠️ Update (2026)
This article was originally written several years ago and uses older 32-bit Linux assembly methods.
While the concepts are still useful for learning, modern Linux systems now use 64-bit architecture by default, and some commands shown below may no longer work as expected.
✅ Recommended Modern Approach
* Use **64-bit assembly (`elf64`)**
* Use **`syscall` instead of `int 0x80`**I
* Use registers like `rax`, `rdi`, `rsi`, `rdx`
🔧 Quick Working Example (64-bit)
```
section .data
msg db "Hello, world!", 10
len equ $ - msg
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, len
syscall
mov rax, 60
xor rdi, rdi
syscall
```
🛠 Compile & Run
```
nasm -f elf64 hello.asm -o hello.o
ld hello.o -o hello
./hello
```
---
📌 Note
The original content below is kept unchanged for reference and for those learning 32-bit assembly, but for modern systems, the updated method above should be used.
It comprises two steps.
1. Compiling with assembler
The assembly language compiler in linux is as. The code to compile a program say helloWorld.s is the following$ as helloWorld.s -o helloWorld.o
2. Linking and Executing the code
The output of assembling is object code which needs linking. The code for linking the object file "helloWorld.o".$ ld -helloWorld.o -o helloWorld.outTo execute the code we need to do the following.
$ ./helloWorld.out
The code for helloWorld.s is attached here and thanks to reference 1.
.text
.global _start
_start:
movl $len,%edx # third argument: message length
movl $msg,%ecx # second argument: pointer to message to write
movl $1,%ebx # first argument: file handle (stdout)
movl $4,%eax # system call number (sys_write)
int $0x80 # call kernel
# and exit
movl $0,%ebx # first argument: exit code
movl $1,%eax # system call number (sys_exit)
int $0x80 # call kernel
.data # section declaration
msg:
.ascii "Hello, world!\n" # our dear string
len = . - msg # length of our dear string
References :
1. http://asm.sourceforge.net/howto/hello.html
3 comments:
Great post, I took your example and made a simple program to read a sudo language and compile it to an executable... Check it out http://spiceycurry.blogspot.com/2010/05/simple-compilable-programming-language.html
also, there is a typo in your post, there is a '-' on the ld line tht should not be there.
Mine (ubuntu 10.04) has to link like this to work.
ld -o helloWorld.out helloWorld.o
--Thanks
lies beyond lies omni get a job
Post a Comment