Protect registers from changes within calls and rename newline to printcrlf for the sake of consistency.

This commit is contained in:
CrazyEttin 2021-06-06 11:18:15 +03:00
parent 9582045822
commit 9065e2c591
9 changed files with 59 additions and 18 deletions

View File

@ -2,6 +2,9 @@
byte2hexstr:
;Store the initial registers in the stack
pusha
;Set a key for the hex digits
mov si, .key
@ -26,6 +29,9 @@ inc di
dec cx
jnz .loop
;Load the initial registers from the stack
popa
ret
.key:

View File

@ -2,6 +2,11 @@
cmpstr:
;Store the initial registers in the stack
pusha
.loop:
;Load characters
mov al, [si]
mov bl, [di]
@ -19,14 +24,20 @@ je .eq
;Repeat
inc si
inc di
jmp cmpstr
jmp .loop
.neq:
;Clear the carry flag
clc
ret
jmp .done
.eq:
;Set the carry flag
stc
.done:
;Load the initial registers from the stack
popa
ret

View File

@ -1,11 +0,0 @@
;Prints a newline
newline:
mov si, .newline
call printstr
ret
.newline:
db 0xd, 0xa, 0x0

18
source/printcrlf.inc Normal file
View File

@ -0,0 +1,18 @@
;Prints a newline
printcrlf:
;Store the initial registers in the stack
pusha
;Print the newline
mov si, .crlf
call printstr
;Load the initial registers from the stack
popa
ret
.crlf:
db 0xd, 0xa, 0x0

View File

@ -1,4 +1,4 @@
;Prints a string from si until a null followed by a newline.
;Prints a string from si until a null, followed by a newline.
println:
@ -6,6 +6,6 @@ println:
call printstr
;Print a newline
call newline
call printcrlf
ret

View File

@ -2,6 +2,11 @@
printstr:
;Store the initial registers in the stack
pusha
.loop:
;Load a character
lodsb
@ -11,10 +16,15 @@ je .done
;Print the character
mov ah, 0xe
mov bx, 0x0
int 0x10
;Repeat
jmp printstr
jmp .loop
.done:
;Load the initial registers from the stack
popa
ret

View File

@ -6,6 +6,6 @@ readln:
call readstr
;Print a newline
call newline
call printcrlf
ret

View File

@ -2,6 +2,9 @@
readstr:
;Store the initial registers in the stack
pusha
;Store the input length in the stack
mov ah, 0
push ax
@ -117,6 +120,10 @@ inc bl
jmp .findend
.done:
;Load the initial registers from the stack
popa
ret
.nextchar:

View File

@ -2,11 +2,11 @@
jmp start
;Calls
%include "printcrlf.inc"
%include "printstr.inc"
%include "println.inc"
%include "readstr.inc"
%include "readln.inc"
%include "newline.inc"
%include "cmpstr.inc"
%include "byte2hexstr.inc"