Added support for \n, \t and \\ in the string printing function

This commit is contained in:
2025-11-01 12:38:02 +00:00
parent 015d4d1fce
commit 7906c48a2e
8 changed files with 125 additions and 85 deletions

View File

@@ -1,4 +1,7 @@
; SI = pointer to start of string to be printed
; \n for newline
; \t for tab
; \\ for a single backslash
os_print_string:
pusha
@@ -8,34 +11,43 @@ os_print_string:
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
; Exact same as the above procedure, but this adds a newline
; after priting, similar to the difference between Rust's print! and println!
os_print_string_nl:
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
int 10h ; Otherwise, print it
jmp .repeat ; And move on to next char
.done:
call os_print_newline
popa
ret
; --------------------------------------------
os_print_newline: