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:
|
byte2hexstr:
|
||||||
|
|
||||||
|
;Store the initial registers in the stack
|
||||||
|
pusha
|
||||||
|
|
||||||
;Set a key for the hex digits
|
;Set a key for the hex digits
|
||||||
mov si, .key
|
mov si, .key
|
||||||
|
|
||||||
|
@ -26,6 +29,9 @@ inc di
|
||||||
dec cx
|
dec cx
|
||||||
jnz .loop
|
jnz .loop
|
||||||
|
|
||||||
|
;Load the initial registers from the stack
|
||||||
|
popa
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.key:
|
.key:
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
cmpstr:
|
cmpstr:
|
||||||
|
|
||||||
|
;Store the initial registers in the stack
|
||||||
|
pusha
|
||||||
|
|
||||||
|
.loop:
|
||||||
|
|
||||||
;Load characters
|
;Load characters
|
||||||
mov al, [si]
|
mov al, [si]
|
||||||
mov bl, [di]
|
mov bl, [di]
|
||||||
|
@ -19,14 +24,20 @@ je .eq
|
||||||
;Repeat
|
;Repeat
|
||||||
inc si
|
inc si
|
||||||
inc di
|
inc di
|
||||||
jmp cmpstr
|
jmp .loop
|
||||||
|
|
||||||
.neq:
|
.neq:
|
||||||
;Clear the carry flag
|
;Clear the carry flag
|
||||||
clc
|
clc
|
||||||
ret
|
jmp .done
|
||||||
|
|
||||||
.eq:
|
.eq:
|
||||||
;Set the carry flag
|
;Set the carry flag
|
||||||
stc
|
stc
|
||||||
|
|
||||||
|
.done:
|
||||||
|
|
||||||
|
;Load the initial registers from the stack
|
||||||
|
popa
|
||||||
|
|
||||||
ret
|
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:
|
println:
|
||||||
|
|
||||||
|
@ -6,6 +6,6 @@ println:
|
||||||
call printstr
|
call printstr
|
||||||
|
|
||||||
;Print a newline
|
;Print a newline
|
||||||
call newline
|
call printcrlf
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
printstr:
|
printstr:
|
||||||
|
|
||||||
|
;Store the initial registers in the stack
|
||||||
|
pusha
|
||||||
|
|
||||||
|
.loop:
|
||||||
|
|
||||||
;Load a character
|
;Load a character
|
||||||
lodsb
|
lodsb
|
||||||
|
|
||||||
|
@ -11,10 +16,15 @@ je .done
|
||||||
|
|
||||||
;Print the character
|
;Print the character
|
||||||
mov ah, 0xe
|
mov ah, 0xe
|
||||||
|
mov bx, 0x0
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
;Repeat
|
;Repeat
|
||||||
jmp printstr
|
jmp .loop
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
|
;Load the initial registers from the stack
|
||||||
|
popa
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -6,6 +6,6 @@ readln:
|
||||||
call readstr
|
call readstr
|
||||||
|
|
||||||
;Print a newline
|
;Print a newline
|
||||||
call newline
|
call printcrlf
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
readstr:
|
readstr:
|
||||||
|
|
||||||
|
;Store the initial registers in the stack
|
||||||
|
pusha
|
||||||
|
|
||||||
;Store the input length in the stack
|
;Store the input length in the stack
|
||||||
mov ah, 0
|
mov ah, 0
|
||||||
push ax
|
push ax
|
||||||
|
@ -117,6 +120,10 @@ inc bl
|
||||||
jmp .findend
|
jmp .findend
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
|
;Load the initial registers from the stack
|
||||||
|
popa
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.nextchar:
|
.nextchar:
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
jmp start
|
jmp start
|
||||||
|
|
||||||
;Calls
|
;Calls
|
||||||
|
%include "printcrlf.inc"
|
||||||
%include "printstr.inc"
|
%include "printstr.inc"
|
||||||
%include "println.inc"
|
%include "println.inc"
|
||||||
%include "readstr.inc"
|
%include "readstr.inc"
|
||||||
%include "readln.inc"
|
%include "readln.inc"
|
||||||
%include "newline.inc"
|
|
||||||
%include "cmpstr.inc"
|
%include "cmpstr.inc"
|
||||||
%include "byte2hexstr.inc"
|
%include "byte2hexstr.inc"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue