Files
crawos/source/kernel/features/strings.asm

50 lines
1019 B
NASM
Executable File

; How string comparison works
; DI => scasb compares value stored in DI which is 's' with 's' stored in AX register
; and then increments DI if DF is 0
; v
; memory address 1: |s|n|a|t|0|
; memory address 2: |s|n|a|k|e|0|
; ^
; SI => lodsb loads value stored at SI to AX and then increments SI if DF is 0
os_compare_strings:
cld
.compare:
lodsb
scasb ; Compare di to si
jne .unequal ; If they are not equal, jump to .unequal
cmp al, 0 ; Check if string is finished
je .equal ; If it has, return true
jmp .compare ; Finally, repeat
.unequal:
mov cl, 0 ; Change to 0 if unquality is proven
ret
.equal:
mov cl, 1
ret
; Convert a string to all upper case
os_upper_case:
pusha
mov di, si
.loop:
lodsb
inc di
cmp al, 0
je .finish
cmp al, 7Ah
jns .loop
cmp al, 61h
js .loop
sub al, 20h
dec di
stosb
jmp .loop
.finish:
popa
ret