add kernel
This commit is contained in:
parent
5be9186a2d
commit
63c3e63fe5
1 changed files with 62 additions and 0 deletions
62
src/kernel.asm
Normal file
62
src/kernel.asm
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue