108 lines
2.0 KiB
NASM
Executable File
108 lines
2.0 KiB
NASM
Executable File
; SI = pointer to start of string to be printed
|
|
; \n for newline
|
|
; \t for tab
|
|
; \\ for a single backslash
|
|
os_print_string:
|
|
pusha
|
|
|
|
mov ah, 0Eh ; int 10h teletype function, we're telling the BIOS we will print something
|
|
|
|
.repeat:
|
|
lodsb ; Get char from si into al
|
|
cmp al, 0 ; Compare al to 0
|
|
je .done ; If char is zero, end of string
|
|
cmp al, 5Ch ; backslash
|
|
je .backslash
|
|
|
|
int 10h ; Otherwise, print it
|
|
jmp .repeat ; And move on to next char
|
|
|
|
.backslash: ; If there is a '\', do what it says, \n for newline, \t for tab etc
|
|
lodsb
|
|
dec si
|
|
cmp al, 6Eh ; 'n'
|
|
je .newline
|
|
cmp al, 74h ; \t
|
|
je .tab
|
|
cmp al, 5Ch ; '\'
|
|
je .another_backslash
|
|
jmp .repeat
|
|
.newline:
|
|
mov al, 0Ah ; new line
|
|
int 10h
|
|
mov al, 0Dh ; carriage return
|
|
int 10h
|
|
jmp .finish_backslash
|
|
.tab:
|
|
mov al, 09h ; tab
|
|
int 10h
|
|
jmp .finish_backslash
|
|
.another_backslash: ; This just prints 1 backslash
|
|
mov al, 5Ch
|
|
int 10h
|
|
jmp .finish_backslash
|
|
.finish_backslash:
|
|
inc si
|
|
jmp .repeat
|
|
.done:
|
|
popa
|
|
ret
|
|
|
|
; This is similar to the previous, however it prints
|
|
; raw output (including null) and prints the number
|
|
; of character defined by ax
|
|
; IN:
|
|
; SI = pointer to start of string to be printed
|
|
; AX = Length of string to print
|
|
text_raw_output:
|
|
pusha
|
|
|
|
mov di, ax
|
|
|
|
mov ah, 0Eh ; int 10h teletype function, we're telling the BIOS we will print something
|
|
|
|
.repeat:
|
|
lodsb ; Get char from si into al
|
|
int 10h ; Otherwise, print it
|
|
dec di
|
|
cmp di, 00h
|
|
je .done
|
|
jne .repeat
|
|
.done:
|
|
popa
|
|
ret
|
|
|
|
|
|
; --------------------------------------------
|
|
|
|
os_print_newline:
|
|
pusha
|
|
|
|
mov ah, 0Eh
|
|
mov al, 13
|
|
int 10h
|
|
mov al, 10
|
|
int 10h
|
|
|
|
popa
|
|
ret
|
|
|
|
; -------------------------------------------
|
|
|
|
os_set_text_mode:
|
|
pusha
|
|
; Set mode = 80x25 (text mode)
|
|
mov ah, 00h
|
|
mov al, 03h
|
|
int 10h
|
|
|
|
; Move cursor to the top left
|
|
mov ah, 02h
|
|
mov dh, 0
|
|
mov dl, 0
|
|
int 10h
|
|
|
|
popa
|
|
ret
|
|
|