Assembler Hello, World! Using Syscall
;; Hello world! using syscalls. Modified from:
;; http://www.linuxgazette.com/issue53/boldyshev.html
;; Author: Konstantin Boldyshev
section .text ; Code section
global _start ; Linker needs this symbol.
;; This is the starting symbol. In a C program, _start is a library function
;; which perfoms initialization, then calls main. For this, we'll just start
;; here.
_start:
;; Load the syscall parameters into expected CPU registers. Linux looks
;; for the syscall code in eax, and any parameters in ebx, ecx, edx,
;; esi, edi and edp, in that order.
mov ebx, 1 ; First parm, file stream 1 (standard output)
mov ecx, msg ; Second parm, pointer to the buffer.
mov edx, len ; Third parm, message length.
mov eax, 4 ; Syscall number (sys_write).
int 0x80 ; Syscall instruction. Enters kernel.
;; Now we need to exit. Just falling off the end won't work. Need
;; to tell the kernel that we need terminating.
mov eax,1 ; System call number (sys_exit)
int 0x80 ; Syscall instruction.
section .data ; Data section
;; This declares a string of characters to write, and computes its length.
msg: db 'Hello, world!',0xa ;
len: equ $ - msg ;