From s23
Jump to navigation Jump to search

This is an example of "Hello Fnord" in Assembler:

vi hello.asm


section .data                     ;section declaration
msg db "Hello, fnord!"       ;der String
section .text                     ;section declaration
global _start                    ;default Eingangspunkt fuer ELF-Link


;write() call

mov eax, 4                    ;4 in eax, weil write syscall #4 ist
mov ebx, 1                    ;stdout in ebx, weil die richtige fd 1 ist
mov ecx, msg                ;die Adresse des Strings in ecx
mov edx, 13                  ;13 in edx, weil der String 13 Bytes enthaelt
int 0x80                        ;Kernelaufruf, um den System-Call auszuloesen

; exit() call

mov eax,1                    ;1 in eax, weil exit syscall #1 ist
mov ebx,0                    ;0 in ebx
int 0x80                       ;Kernelaufruf, um den System-Call auszuloesen


put this into hello.asm then compile it with nasm

$ nasm -f elf hello.asm

link it

$ ld hello.o

run it

$ ./a.out

Hello, fnord!

tataaaa! you wrote your first assembler program.