Implement bcdDigitAdd3 in calculator.asm
This commit is contained in:
parent
95b7c676b2
commit
108bf334e8
|
@ -438,8 +438,8 @@ fResult:
|
||||||
; Arithmetic
|
; Arithmetic
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
; x y -- tens(x+y) ones(x+y)
|
; x y z -- tens(x+y+z) ones(x+y+z)
|
||||||
bcdDigitAdd:
|
bcdDigitAdd3:
|
||||||
cleq r0, r0, stAdd
|
cleq r0, r0, stAdd
|
||||||
|
|
||||||
cleq r0, r0, stDup
|
cleq r0, r0, stDup
|
||||||
|
@ -447,18 +447,43 @@ bcdDigitAdd:
|
||||||
load r1, #a
|
load r1, #a
|
||||||
cleq r0, r0, pushWord
|
cleq r0, r0, pushWord
|
||||||
cleq r0, r0, stGtEq
|
cleq r0, r0, stGtEq
|
||||||
|
breq r0, r1, bcdDigitAdd
|
||||||
|
|
||||||
|
; Adjust so that carry is in the high 3 bits
|
||||||
|
; Basically we want 9+1=a₁₆ to become 20₁₆
|
||||||
|
xor r0, r0
|
||||||
|
load r1, #16
|
||||||
|
cleq r0, r0, pushWord
|
||||||
|
cleq r0, r0, stAdd
|
||||||
|
|
||||||
|
; x y -- tens(x+y) ones(x+y)
|
||||||
|
bcdDigitAdd:
|
||||||
|
cleq r0, r0, stAdd
|
||||||
|
|
||||||
|
cleq r0, r0, stDup
|
||||||
|
; Only look at the bottom 5 bits, since high 3 bits may already
|
||||||
|
; contain carry
|
||||||
|
cleq r0, r0, popWord
|
||||||
|
load r2, #1f
|
||||||
|
and r1, r2
|
||||||
|
cleq r0, r0, pushWord
|
||||||
|
xor r0, r0
|
||||||
|
load r1, #a
|
||||||
|
cleq r0, r0, pushWord
|
||||||
|
cleq r0, r0, stGtEq
|
||||||
breq r0, r1, bcdDigitAddNoAdjust
|
breq r0, r1, bcdDigitAddNoAdjust
|
||||||
|
|
||||||
; Adjust so that carry is in the high nybble
|
; Adjust so that carry is in the high 3 bits
|
||||||
; Basically we want 9+1=a₁₆ to become 10₁₆
|
; Basically we want 9+1=a₁₆ to become 20₁₆
|
||||||
xor r0, r0
|
xor r0, r0
|
||||||
load r1, #6
|
load r1, #16
|
||||||
cleq r0, r0, pushWord
|
cleq r0, r0, pushWord
|
||||||
cleq r0, r0, stAdd
|
cleq r0, r0, stAdd
|
||||||
|
|
||||||
bcdDigitAddNoAdjust:
|
bcdDigitAddNoAdjust:
|
||||||
cleq r0, r0, stDup
|
cleq r0, r0, stDup
|
||||||
cleq r0, r0, stShr4
|
cleq r0, r0, stShr4
|
||||||
|
cleq r0, r0, stShr1
|
||||||
cleq r0, r0, stSwap
|
cleq r0, r0, stSwap
|
||||||
breq r0, r0, stLowNybble
|
breq r0, r0, stLowNybble
|
||||||
|
|
||||||
|
@ -618,11 +643,7 @@ fPrint:
|
||||||
; added to the corresponding minuend. This by itself gives a
|
; added to the corresponding minuend. This by itself gives a
|
||||||
; result that is one too small, so we add one to it (c.f. binary
|
; result that is one too small, so we add one to it (c.f. binary
|
||||||
; subtraction, where we negate the subtrahend and then add one).
|
; subtraction, where we negate the subtrahend and then add one).
|
||||||
; Normally we'd have to split subtraction into two rounds, one
|
; 500 + 1 + 999 - biased
|
||||||
; to add the complemented subtrahend and one to add the 1, but
|
|
||||||
; since our minuend is a constant, we can add 1 to it instead.
|
|
||||||
; 501 + 999 - biased
|
|
||||||
; = 500 + 1 + 999 - biased
|
|
||||||
; = 500 + 1000 - biased (1000 = 0 mod 1000)
|
; = 500 + 1000 - biased (1000 = 0 mod 1000)
|
||||||
; = 500 - biased
|
; = 500 - biased
|
||||||
|
|
||||||
|
@ -649,14 +670,11 @@ fPrint:
|
||||||
xor r0, r0
|
xor r0, r0
|
||||||
load r1, #5
|
load r1, #5
|
||||||
cleq r0, r0, pushWord
|
cleq r0, r0, pushWord
|
||||||
cleq r0, r0, bcdDigitAdd
|
|
||||||
cleq r0, r0, stSwap
|
|
||||||
cleq r0, r0, popWord
|
|
||||||
xor r0, r0
|
xor r0, r0
|
||||||
load r1, fArg1+1
|
load r1, fArg1+1
|
||||||
cleq r0, r0, pushWord
|
cleq r0, r0, pushWord
|
||||||
cleq r0, r0, bcdDigit9sComplement
|
cleq r0, r0, bcdDigit9sComplement
|
||||||
cleq r0, r0, bcdDigitAdd
|
cleq r0, r0, bcdDigitAdd3
|
||||||
cleq r0, r0, stSwap
|
cleq r0, r0, stSwap
|
||||||
cleq r0, r0, popWord
|
cleq r0, r0, popWord
|
||||||
|
|
||||||
|
@ -779,6 +797,18 @@ stShr4:
|
||||||
shr r0, 4
|
shr r0, 4
|
||||||
breq r0, r0, pushWord
|
breq r0, r0, pushWord
|
||||||
|
|
||||||
|
; a -- a>>1
|
||||||
|
stShr1:
|
||||||
|
cleq r0, r0, popWord
|
||||||
|
shr r1, 1
|
||||||
|
xor r2, r2
|
||||||
|
or r2, r0
|
||||||
|
shl r2, 4
|
||||||
|
shl r2, 3
|
||||||
|
or r1, r2
|
||||||
|
shr r0, 1
|
||||||
|
breq r0, r0, pushWord
|
||||||
|
|
||||||
; a -- a&f
|
; a -- a&f
|
||||||
stLowNybble:
|
stLowNybble:
|
||||||
cleq r0, r0, popWord
|
cleq r0, r0, popWord
|
||||||
|
|
Loading…
Reference in New Issue