Add looping and ability to correct input to the adder
This commit is contained in:
parent
1a3f010dd0
commit
9474cb7864
|
@ -1,23 +1,12 @@
|
|||
;Two-digit hexadecimal adder
|
||||
|
||||
;Print a prompt
|
||||
load r0, prompt
|
||||
start: load r0, prompt
|
||||
store ffff, r0
|
||||
|
||||
;Read and convert the first argument and load it to r2
|
||||
;First digit
|
||||
load r0, ffff
|
||||
cleq r0, r0, hex2n
|
||||
xor r2, r2
|
||||
xor r2, r0
|
||||
shl r2
|
||||
shl r2
|
||||
shl r2
|
||||
shl r2
|
||||
;Second digit
|
||||
load r0, ffff
|
||||
cleq r0, r0, hex2n
|
||||
or r2, r0
|
||||
;Read and convert the first argument and store it to arg1
|
||||
cleq r0, r0, rarg
|
||||
store arg1, r0
|
||||
|
||||
;Print a newline
|
||||
cleq r0, r0, newln
|
||||
|
@ -26,20 +15,13 @@
|
|||
load r0, plus
|
||||
store ffff, r0
|
||||
|
||||
;Read and convert the second argument and load it to r0
|
||||
;First digit
|
||||
load r0, ffff
|
||||
cleq r0, r0, hex2n
|
||||
xor r3, r3
|
||||
xor r3, r0
|
||||
shl r3
|
||||
shl r3
|
||||
shl r3
|
||||
shl r3
|
||||
;Second digit
|
||||
load r0, ffff
|
||||
cleq r0, r0, hex2n
|
||||
or r0, r3
|
||||
;Read and convert the second argument and load it to r2
|
||||
cleq r0, r0, rarg
|
||||
xor r2, r2
|
||||
xor r2, r0
|
||||
|
||||
;Reload the first argument to r0
|
||||
load r0, arg1
|
||||
|
||||
;Print a newline
|
||||
cleq r0, r0, newln
|
||||
|
@ -74,8 +56,38 @@
|
|||
;Print a newline
|
||||
cleq r0, r0, newln
|
||||
|
||||
;Halt
|
||||
;Loop
|
||||
breq r0, r0, start
|
||||
|
||||
;Read and convert an argument and load it to r0
|
||||
;First digit
|
||||
rarg: load r0, ffff
|
||||
cleq r0, r0, hex2n
|
||||
xor r2, r2
|
||||
xor r2, r0
|
||||
shl r2
|
||||
shl r2
|
||||
shl r2
|
||||
shl r2
|
||||
;Second digit
|
||||
rarg2: load r0, ffff
|
||||
load r1, backsp
|
||||
breq r0, r1, rarg
|
||||
cleq r0, r0, hex2n
|
||||
;Confirm
|
||||
load r3, ffff
|
||||
load r1, backsp
|
||||
breq r3, r1, rarg2
|
||||
load r1, cr
|
||||
breq r3, r1, rarg3
|
||||
load r0, qmark
|
||||
store ffff, r0
|
||||
cleq r0, r0, newln
|
||||
halt
|
||||
;Combine the digits
|
||||
rarg3: or r0, r2
|
||||
;Return
|
||||
ret
|
||||
|
||||
;Print a newline
|
||||
newln: load r1, cr
|
||||
|
@ -265,6 +277,7 @@ prompt: data 3e
|
|||
plus: data 2b
|
||||
equals: data 3d
|
||||
qmark: data 3f
|
||||
backsp: data 8
|
||||
cr: data d
|
||||
lf: data a
|
||||
|
||||
|
@ -319,3 +332,6 @@ tbl28: data e
|
|||
tbl29: data 65
|
||||
tbl2a: data f
|
||||
tbl2b: data 66
|
||||
|
||||
;First argument
|
||||
arg1: data 0
|
||||
|
|
Loading…
Reference in New Issue