Implement subWord, stSub, stGtEq in calculator.asm
This commit is contained in:
parent
34c3fa70e3
commit
b63232169d
|
@ -35,17 +35,27 @@ stAdd:
|
||||||
|
|
||||||
; a b -- a-b
|
; a b -- a-b
|
||||||
stSub:
|
stSub:
|
||||||
cleq r0, r0, stNeg
|
|
||||||
breq r0, r0, stAdd
|
|
||||||
|
|
||||||
; n -- -n
|
|
||||||
stNeg:
|
|
||||||
cleq r0, r0, popWord
|
cleq r0, r0, popWord
|
||||||
nand r0, r0
|
cleq r0, r0, tmpStoreWord01
|
||||||
nand r1, r1
|
cleq r0, r0, popWord
|
||||||
cleq r0, r0, incWord
|
cleq r0, r0, tmpLoadWord23
|
||||||
|
cleq r0, r0, subWord
|
||||||
breq r0, r0, pushWord
|
breq r0, r0, pushWord
|
||||||
|
|
||||||
|
; a b --
|
||||||
|
; if a >= b then r0:r1 = 0001
|
||||||
|
; else r0:r1 = 0000
|
||||||
|
stGtEq:
|
||||||
|
cleq r0, r0, popWord
|
||||||
|
cleq r0, r0, tmpStoreWord01
|
||||||
|
cleq r0, r0, popWord
|
||||||
|
cleq r0, r0, tmpLoadWord23
|
||||||
|
cleq r0, r0, subWord
|
||||||
|
xor r0, r0
|
||||||
|
xor r1, r1
|
||||||
|
or r1, r2
|
||||||
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; I/O
|
; I/O
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
@ -228,6 +238,45 @@ addWord:
|
||||||
addWordSecondHigh: data 0
|
addWordSecondHigh: data 0
|
||||||
addWordResultLow: data 0
|
addWordResultLow: data 0
|
||||||
|
|
||||||
|
; in:
|
||||||
|
; r0:r1 = minuend
|
||||||
|
; r2:r3 = subtrahend
|
||||||
|
; out:
|
||||||
|
; r0:r1 = result
|
||||||
|
; r2 = carryout
|
||||||
|
; trashes:
|
||||||
|
; r3
|
||||||
|
subWord:
|
||||||
|
store subWordMinuendHigh, r0
|
||||||
|
store subWordSubtrahendHigh, r2
|
||||||
|
|
||||||
|
; Subtract low bytes
|
||||||
|
; a - b = a + (-b) = a + ~b + 1
|
||||||
|
xor r0, r0
|
||||||
|
or r0, r3
|
||||||
|
nand r0, r0
|
||||||
|
load r2, lit01
|
||||||
|
cleq r0, r0, addByte3
|
||||||
|
store subWordResultLow, r0
|
||||||
|
|
||||||
|
; Subtract high bytes with carry-in in r1
|
||||||
|
load r0, subWordMinuendHigh
|
||||||
|
load r2, subWordSubtrahendHigh
|
||||||
|
nand r2, r2
|
||||||
|
cleq r0, r0, addByte3
|
||||||
|
|
||||||
|
; Move carryout to r2
|
||||||
|
xor r2, r2
|
||||||
|
or r2, r1
|
||||||
|
|
||||||
|
load r1, subWordResultLow
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
|
subWordMinuendHigh: data 0
|
||||||
|
subWordSubtrahendHigh: data 0
|
||||||
|
subWordResultLow: data 0
|
||||||
|
|
||||||
; in/out:
|
; in/out:
|
||||||
; r0:r1 = word
|
; r0:r1 = word
|
||||||
; trashes:
|
; trashes:
|
||||||
|
|
Loading…
Reference in New Issue