You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

5 years ago
BITS 16
5 years ago
5 years ago
5 years ago
start:
5 years ago
mov ax, 07C0h ; Set up 4K stack space after this bootloader
5 years ago
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
5 years ago
mov ax, 07C0h ; Set data segment to where we're loaded
add ax, 255
mov ds, ax
5 years ago
5 years ago
main_loop:
5 years ago
call read_char ; Read character
jmp main_loop ; Repeat
read_char:
mov ah, 0h ; Call Function "Read Char"
int 16h ; Execute Keyboard Services
mov ah, 0eh ; Call Function "Write char to TTY
int 10h ; Execute Video Services
5 years ago
5 years ago
cmp AL, 0x0d ; Insert new line, if keystroke was return
je new_line
5 years ago
5 years ago
ret
5 years ago
5 years ago
new_line:
mov AH, 03h ; Get Cursor position
int 10h
5 years ago
5 years ago
add DH, 1 ; Add 1 to cursor position
5 years ago
5 years ago
mov AH, 02h ; Set Cursor to new position
int 10h
ret
print_string: ; Routine: output string in SI to screen
5 years ago
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
5 years ago