Compare commits

...

4 Commits

Author SHA1 Message Date
Juhani Krekelä c89d8e9850 Change trashes → clobbers in calculator.asm 2022-08-17 02:33:49 +03:00
Juhani Krekelä cc933eeac1 Add missing trashes: entry for peekWord in calculator.asm 2022-08-17 02:32:51 +03:00
Juhani Krekelä b63232169d Implement subWord, stSub, stGtEq in calculator.asm 2022-08-17 02:32:26 +03:00
Juhani Krekelä 34c3fa70e3 Use addr statement in calculator.asm 2022-08-09 00:44:14 +03:00
1 changed files with 84 additions and 48 deletions

View File

@ -1,8 +1,6 @@
org 0 org 0
start: start:
cleq r0, r0, initStack
load r0, lit01 load r0, lit01
load r1, litff load r1, litff
cleq r0, r0, pushWord cleq r0, r0, pushWord
@ -37,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
; ------------------------------------------------------------------ ; ------------------------------------------------------------------
@ -83,6 +91,8 @@ tmpWordLow: data 0
; out: ; out:
; r0:r1 = word ; r0:r1 = word
; clobbers:
; r2, r3
peekWord: peekWord:
cleq r0, r0, popWord cleq r0, r0, popWord
cleq r0, r0, tmpStoreWord01 cleq r0, r0, tmpStoreWord01
@ -112,7 +122,7 @@ tmpLoadWord23:
; in: ; in:
; r0:r1 = word ; r0:r1 = word
; trashes: ; clobbers:
; r0, r1, r2, r3 ; r0, r1, r2, r3
pushWord: pushWord:
store pushWordLow, r1 store pushWordLow, r1
@ -124,7 +134,7 @@ pushWord:
; out: ; out:
; r0:r1 ; r0:r1
; trashes: ; clobbers:
; r2, r3 ; r2, r3
popWord: popWord:
cleq r0, r0, popByte cleq r0, r0, popByte
@ -140,33 +150,33 @@ popWord:
; in: ; in:
; r0 = byte ; r0 = byte
; trashes: ; clobbers:
; r0, r1, r2, r3 ; r0, r1, r2, r3
pushByte: pushByte:
load r2, SPHigh load r2, SP+0
store storeByteHigh, r2 store storeByteHigh, r2
load r3, SPLow load r3, SP+1
store storeByteLow, r3 store storeByteLow, r3
cleq r0, r0, storeByte cleq r0, r0, storeByte
load r0, SPHigh load r0, SP+0
load r1, SPLow load r1, SP+1
cleq r0, r0, incWord cleq r0, r0, incWord
store SPHigh, r0 store SP+0, r0
store SPLow, r1 store SP+1, r1
ret ret
; out: ; out:
; r0 = byte ; r0 = byte
; trashes: ; clobbers:
; r1, r2, r3 ; r1, r2, r3
popByte: popByte:
load r0, SPHigh load r0, SP+0
load r1, SPLow load r1, SP+1
cleq r0, r0, decWord cleq r0, r0, decWord
store SPHigh, r0 store SP+0, r0
store SPLow, r1 store SP+1, r1
store loadByteHigh, r0 store loadByteHigh, r0
store loadByteLow, r1 store loadByteLow, r1
@ -201,7 +211,7 @@ loadByte:
; out: ; out:
; r0:r1 = result ; r0:r1 = result
; r2 = carryout ; r2 = carryout
; trashes: ; clobbers:
; r3 ; r3
addWord: addWord:
store addWordFirstHigh, r0 store addWordFirstHigh, r0
@ -230,9 +240,48 @@ 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
; clobbers:
; 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: ; clobbers:
; r2, r3 ; r2, r3
incWord: incWord:
store incWordHigh, r0 store incWordHigh, r0
@ -255,7 +304,7 @@ incWord:
; in/out: ; in/out:
; r0:r1 = word ; r0:r1 = word
; trashes: ; clobbers:
; r2, r3 ; r2, r3
decWord: decWord:
store decWordHigh, r0 store decWordHigh, r0
@ -284,7 +333,7 @@ decWord:
; out: ; out:
; r0 = result ; r0 = result
; r1 = carryout ; r1 = carryout
; trashes: ; clobbers:
; r2, r3 ; r2, r3
addByte3: addByte3:
store addByte3ThirdAddend, r2 store addByte3ThirdAddend, r2
@ -309,7 +358,7 @@ addByte3:
; out: ; out:
; r0 = result ; r0 = result
; r1 = carryout ; r1 = carryout
; trashes: ; clobbers:
; r2, r3 ; r2, r3
addByte: addByte:
; Initiliaze carryout to 0 ; Initiliaze carryout to 0
@ -356,7 +405,7 @@ addByte:
; r0 = number in range [0, 0xf] ; r0 = number in range [0, 0xf]
; out: ; out:
; r0 = ascii character corresponding to input ; r0 = ascii character corresponding to input
; trashes: ; clobbers:
; r3 ; r3
nybble2hex: nybble2hex:
xor r3, r3 xor r3, r3
@ -447,7 +496,7 @@ nybble2hex:
; r0 = ascii hex digit ; r0 = ascii hex digit
; out: ; out:
; r0 = corresponding nybble ; r0 = corresponding nybble
; trashes: ; clobbers:
; r3 ; r3
hex2nybble: hex2nybble:
load r3, litchar0 load r3, litchar0
@ -552,7 +601,7 @@ hex2nybble:
; in: ; in:
; r1:r0 = word ; r1:r0 = word
; trashes: ; clobbers:
; r0, r2, r3 ; r0, r2, r3
writehexWord: writehexWord:
cleq r0, r0, writehexByte cleq r0, r0, writehexByte
@ -564,7 +613,7 @@ writehexWord:
; in: ; in:
; r0 = byte ; r0 = byte
; trashes: ; clobbers:
; r0, r2, r3 ; r0, r2, r3
writehexByte: writehexByte:
; Store copy of the byte (as r0 is modified by nybble2hex) ; Store copy of the byte (as r0 is modified by nybble2hex)
@ -591,7 +640,7 @@ writehexByte:
; Common output routines ; Common output routines
; ------------------------------------------------------------------ ; ------------------------------------------------------------------
; trashes: ; clobbers:
; r3 ; r3
newline: newline:
load r3, litcharCR load r3, litcharCR
@ -695,18 +744,5 @@ litff: data ff
; Stack ; Stack
; ================================================================== ; ==================================================================
SPHigh: data 0 SP: addr stackBase
SPLow: data 0
; trashes:
; r3
initStack:
load r3, initStackDummyLoad+1
store SPHigh, r3
load r3, initStackDummyLoad+2
store SPLow, r3
ret
initStackDummyLoad: load r0, stackBase
stackBase: stackBase: