Add third byte to the result in the adder
This commit is contained in:
parent
9474cb7864
commit
674ba2df08
1 changed files with 41 additions and 16 deletions
|
@ -3,6 +3,8 @@
|
||||||
;Print a prompt
|
;Print a prompt
|
||||||
start: load r0, prompt
|
start: load r0, prompt
|
||||||
store ffff, r0
|
store ffff, r0
|
||||||
|
load r0, space
|
||||||
|
store ffff, r0
|
||||||
|
|
||||||
;Read and convert the first argument and store it to arg1
|
;Read and convert the first argument and store it to arg1
|
||||||
cleq r0, r0, rarg
|
cleq r0, r0, rarg
|
||||||
|
@ -14,6 +16,8 @@ start: load r0, prompt
|
||||||
;Print a plus sign
|
;Print a plus sign
|
||||||
load r0, plus
|
load r0, plus
|
||||||
store ffff, r0
|
store ffff, r0
|
||||||
|
load r0, space
|
||||||
|
store ffff, r0
|
||||||
|
|
||||||
;Read and convert the second argument and load it to r2
|
;Read and convert the second argument and load it to r2
|
||||||
cleq r0, r0, rarg
|
cleq r0, r0, rarg
|
||||||
|
@ -26,16 +30,21 @@ start: load r0, prompt
|
||||||
;Print a newline
|
;Print a newline
|
||||||
cleq r0, r0, newln
|
cleq r0, r0, newln
|
||||||
|
|
||||||
|
;Print an equals sign
|
||||||
|
load r3, equals
|
||||||
|
store ffff, r3
|
||||||
|
|
||||||
;Add the arguments and load the result to r3
|
;Add the arguments and load the result to r3
|
||||||
cleq r0, r0, adder
|
cleq r0, r0, adder
|
||||||
xor r3, r3
|
xor r3, r3
|
||||||
xor r3, r0
|
xor r3, r0
|
||||||
|
|
||||||
;Print an equals sign
|
|
||||||
load r0, equals
|
|
||||||
store ffff, r0
|
|
||||||
|
|
||||||
;Convert and print the result
|
;Convert and print the result
|
||||||
|
;Overflow
|
||||||
|
xor r0, r0
|
||||||
|
xor r0, r1
|
||||||
|
cleq r0, r0, n2hex
|
||||||
|
store ffff, r0
|
||||||
;Restore the result back to r0
|
;Restore the result back to r0
|
||||||
xor r0, r0
|
xor r0, r0
|
||||||
xor r0, r3
|
xor r0, r3
|
||||||
|
@ -90,10 +99,10 @@ rarg3: or r0, r2
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;Print a newline
|
;Print a newline
|
||||||
newln: load r1, cr
|
newln: load r3, cr
|
||||||
store ffff, r1
|
store ffff, r3
|
||||||
load r1, lf
|
load r3, lf
|
||||||
store ffff, r1
|
store ffff, r3
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;Get the value of a hexadecimal digit
|
;Get the value of a hexadecimal digit
|
||||||
|
@ -183,21 +192,32 @@ valf: load r0, tbl1e
|
||||||
;Return
|
;Return
|
||||||
h2nend: ret
|
h2nend: ret
|
||||||
|
|
||||||
;Add r2 to r0
|
;Add r2 to r0 with the overflow stored in r1
|
||||||
|
;Reset overflow
|
||||||
|
adder: xor r3, r3
|
||||||
|
store ovrflw, r3
|
||||||
;Copy the first argument to r1
|
;Copy the first argument to r1
|
||||||
adder: xor r1, r1
|
addlop: xor r1, r1
|
||||||
xor r1, r0
|
xor r1, r0
|
||||||
;Calculate the sum and carry
|
;Calculate the sum and carry and copy the pre-shift carry to r1
|
||||||
xor r0, r2
|
xor r0, r2
|
||||||
and r2, r1
|
and r2, r1
|
||||||
|
xor r1, r1
|
||||||
|
xor r1, r2
|
||||||
shl r2
|
shl r2
|
||||||
|
;Check for overflow
|
||||||
|
rol r1
|
||||||
|
breq r1, r2, nvrflw
|
||||||
|
;Store overflow
|
||||||
|
load r1, one
|
||||||
|
store ovrflw, r1
|
||||||
;Check for no carry
|
;Check for no carry
|
||||||
xor r3, r3
|
nvrflw: breq r2, r3, addend
|
||||||
breq r2, r3, addend
|
|
||||||
;Loop
|
;Loop
|
||||||
breq r0, r0, adder
|
breq r0, r0, addlop
|
||||||
;Return
|
;Load overflow and return
|
||||||
addend: ret
|
addend: load r1, ovrflw
|
||||||
|
ret
|
||||||
|
|
||||||
;Get the hexadecimal digit of a nibble
|
;Get the hexadecimal digit of a nibble
|
||||||
;Extract the low nibble
|
;Extract the low nibble
|
||||||
|
@ -273,6 +293,7 @@ dgtf: load r0, tbl1f
|
||||||
n2hend: ret
|
n2hend: ret
|
||||||
|
|
||||||
;Characters
|
;Characters
|
||||||
|
space: data 20
|
||||||
prompt: data 3e
|
prompt: data 3e
|
||||||
plus: data 2b
|
plus: data 2b
|
||||||
equals: data 3d
|
equals: data 3d
|
||||||
|
@ -284,6 +305,9 @@ lf: data a
|
||||||
;Mask
|
;Mask
|
||||||
mask: data f
|
mask: data f
|
||||||
|
|
||||||
|
;One
|
||||||
|
one: data 1
|
||||||
|
|
||||||
;Hexadecimal table
|
;Hexadecimal table
|
||||||
;Numeric digits
|
;Numeric digits
|
||||||
tbl00: data 0
|
tbl00: data 0
|
||||||
|
@ -334,4 +358,5 @@ tbl2a: data f
|
||||||
tbl2b: data 66
|
tbl2b: data 66
|
||||||
|
|
||||||
;First argument
|
;First argument
|
||||||
|
ovrflw: data 0
|
||||||
arg1: data 0
|
arg1: data 0
|
||||||
|
|
Loading…
Reference in a new issue