Created
March 26, 2021 13:12
-
-
Save netom/44c81ae2c4e7f74de94b68bba49bf8e1 to your computer and use it in GitHub Desktop.
Tiny "Hello World" program for Linux (>=2.2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Credits: https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html | |
; Compile: nasm -f bin -o hello hello.asm | |
BITS 32 | |
org 0x08048000 | |
ehdr: ; Elf32_Ehdr | |
db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident | |
times 8 db 0 | |
dw 2 ; e_type | |
dw 3 ; e_machine | |
dd 1 ; e_version | |
dd _start ; e_entry | |
dd phdr - $$ ; e_phoff | |
dd 0 ; e_shoff | |
dd 0 ; e_flags | |
dw ehdrsize ; e_ehsize | |
dw phdrsize ; e_phentsize | |
dw 1 ; e_phnum | |
dw 0 ; e_shentsize | |
dw 0 ; e_shnum | |
dw 0 ; e_shstrndx | |
ehdrsize equ $ - ehdr | |
phdr: ; Elf32_Phdr | |
dd 1 ; p_type | |
dd 0 ; p_offset | |
dd $$ ; p_vaddr | |
dd $$ ; p_paddr | |
dd filesize ; p_filesz | |
dd filesize ; p_memsz | |
dd 5 ; p_flags | |
dd 0x1000 ; p_align | |
phdrsize equ $ - phdr | |
_start: | |
mov al, 4 ; sys_write( | |
mov bl, 0 ; unsigned int, | |
mov ecx, hello ; const char *, | |
mov dl, 13 ; size_t | |
int 0x80 ; ) | |
xor eax, eax ; sys_exit( | |
inc eax ; int // notice that ebx is still 0 | |
int 0x80 ; ) | |
hello: db `Hello World!\n` | |
filesize equ $ - $$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment