; This program demonstrates basic text output to a screen. ; No "C" library functions are used. ; Calls are made to the operating system directly. (int 80 hex) ; ; assemble: nasm -f elf hello.asm ; link: ld hello.o -o hello ; run: ./hello ; output is: Hello World section .data ; Data section text db "Hello World!", 10 ; The string to print, 10=cr len dd $-text ; "$" means "here" ; len is a value, not an address section .text ; Code section global _start ; Make label available to linker ; We must export the entry point to the ELF linker or ; loader. They conventionally recognize _start as their ; entry point. Use ld -e foo to override the default. _start: ; Standard ld entry point mov edx, [len] ; arg3: length of string to print mov ecx, text ; arg2: pointer to string mov ebx, 1 ; arg1: where to write, so called file handler in this case stdout (screen) mov eax, 4 ; System call number (sys_write) int 0x80 ; Interrupt 80 hex, call kernel ; Exit mov ebx,0 ; Exit code, 0=normal mov eax,1 ; System call number (sys_exit) int 0x80 ; Interrupt 80 hex, call kernel ; End of the code