Protect registers from changes within calls and rename newline to printcrlf for the sake of consistency.
This commit is contained in:
parent
9582045822
commit
9065e2c591
|
@ -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:
|
||||
|
|
|
@ -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
|
|
@ -1,11 +0,0 @@
|
|||
;Prints a newline
|
||||
|
||||
newline:
|
||||
|
||||
mov si, .newline
|
||||
call printstr
|
||||
|
||||
ret
|
||||
|
||||
.newline:
|
||||
db 0xd, 0xa, 0x0
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,6 +6,6 @@ readln:
|
|||
call readstr
|
||||
|
||||
;Print a newline
|
||||
call newline
|
||||
call printcrlf
|
||||
|
||||
ret
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue