From 63c3e63fe590b6ed80d3b18cee3a9810fe6b2ee7 Mon Sep 17 00:00:00 2001 From: Dario48 Date: Tue, 15 Jul 2025 18:26:56 +0200 Subject: [PATCH] add kernel --- src/kernel.asm | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/kernel.asm diff --git a/src/kernel.asm b/src/kernel.asm new file mode 100644 index 0000000..6da1603 --- /dev/null +++ b/src/kernel.asm @@ -0,0 +1,62 @@ +; vim: ft=nasm +org 0x7C00 +bits 16 + +%define ENDL 0x0D, 0x0A + +start: + jmp main + +; +; echo: +; print something to the screen +; - ds:si points to string +; +echo: + ; save the registers we want to modify + push si + push ax + push bx + + mov ah, 0xe + mov bh, 0 + +.loop: + lodsb ; load byte from ds:si to al + or al, al ; check if next char is null + jz .done + + int 0x10 + jmp .loop + +.done: + pop bx + pop ax + pop si + ret + +main: + + ; setup data segments + ; use ax as and intermediary as we can't write to es/ds directly + mov ax, 0 + mov ds, ax + mov es, ax + + ; setup stack + mov ss, ax + mov sp, 0x7C00 ; stack grows downward from where we are loaded in memory + + ; print the hello world + mov si, msg_hello + call echo + + hlt + +.halt: + jmp .halt + +msg_hello: db 'Hello, world!', ENDL, 0 + +times 510-($-$$) db 0 +dw 0AA55h