/
main.asm
55 lines (45 loc) · 1.36 KB
/
main.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
; Te compileren met NASM: nasm -f bin -o allersmaboot.bin main.asm
BITS 16
start:
; Define Stack Space
mov ax, 07C0h ; De initial location van deze bootloader (ax = 0x7C00 / BITS).
add ax, 20h ; Einde bootloader data (ds).
mov ss, ax ; ss = Stack Space Location. Hier begint de stack.
mov sp, 4096 ; Stack Pointer. Werkt achterstevoren; begint dus bij einde.
; Define Data Space
mov ax, 07C0h
mov ds, ax ; ds = Data Space Location. Hier begint de data.
; Print string
mov si, message ; si = Source Index register.
call print
call read
cli ; Disable External interrupts
hlt ; Halt CPU.
data:
message db 'Bootloader booted.',0
nlmsg db 'Pressed ', 39, 'a', 39, '!',0
read:
mov ah, 0h ; Get char (I guess). It is a follow-up for 'int 16h' and further
mov cx, ax ; Set inputted character to cx
cmp cx, 'a' ; if (cx == 'a') {
je .showmsg ; .showmsg }
int 16h ; puts(char)
mov ah, 0Eh;call print ; display(char)
int 10h ; echo char
jmp read ; start over again.
.showmsg:
mov si, nlmsg
call print
jmp read
print:
mov ah, 0Eh
.printchar:
lodsb ; Load byte from Source Index & increment it.
cmp al, 0 ; Compare al with NULL.
je .done ; if(cmp al, 0) { .done; }
int 10h ; puts(loaded_byte);
jmp .printchar
.done:
ret
times 510-($-$$) db 0 ; Fill 510 bytes with this bootloader.
dw 0xAA55 ; Bootloader signature: EOF & Geeft aan dat dit een bootloader is.