Compare commits

...

3 Commits

Author SHA1 Message Date
Juhani Krekelä 9cc8cdef5f Fix an infinite loop bug if rounding overflowed in calculator.asm 2022-09-28 02:15:13 +03:00
Juhani Krekelä 7c9a73cab3 Fix indentation in normalize in calculator.asm 2022-09-28 02:08:57 +03:00
Juhani Krekelä 66dd813d7b Factor out dumpFloat in calculator.asm 2022-09-28 02:08:40 +03:00
1 changed files with 47 additions and 32 deletions

View File

@ -1,35 +1,16 @@
org 0
cleq r0, r0, normalize
xor r0, r0
load r1, #12
cleq r0, r0, pushWord
load r0, fResultPtr+0
load r1, fResultPtr+1
cleq r0, r0, pushWord
dumpFResult:
cleq r0, r0, stSwap
cleq r0, r0, peekWord
or r0, r1
xor r2, r2
breq r0, r2, dumpFResultEnd
cleq r0, r0, stDec
cleq r0, r0, dumpFloat
cleq r0, r0, stSwap
cleq r0, r0, stDup
cleq r0, r0, stLoadByte
cleq r0, r0, popWord
xor r0, r0
or r0, r1
cleq r0, r0, writehexByte
load r0, #20
store ffff, r0
cleq r0, r0, stInc
breq r0, r0, dumpFResult
cleq r0, r0, normalize
dumpFResultEnd:
cleq r0, r0, newline
load r0, fResultPtr+0
load r1, fResultPtr+1
cleq r0, r0, pushWord
cleq r0, r0, dumpFloat
load r0, fResultPtr+0
load r1, fResultPtr+1
@ -78,6 +59,36 @@ printend:
cleq r0, r0, newline
halt
dumpFloat:
xor r0, r0
load r1, #12
cleq r0, r0, pushWord
dumpFloatLoop:
cleq r0, r0, peekWord
or r0, r1
xor r2, r2
breq r0, r2, dumpFloatEnd
cleq r0, r0, stDec
cleq r0, r0, stSwap
cleq r0, r0, stDup
cleq r0, r0, stLoadByte
cleq r0, r0, popWord
xor r0, r0
or r0, r1
cleq r0, r0, writehexByte
load r0, #20
store ffff, r0
cleq r0, r0, stInc
cleq r0, r0, stSwap
breq r0, r0, dumpFloatLoop
dumpFloatEnd:
cleq r0, r0, popWord
cleq r0, r0, popWord
breq r0, r0, newline
debug:
store debugr0, r0
store debugr1, r1
@ -453,7 +464,7 @@ fResult:
data 05 ; exponent
data 00
data 00
data 00 ; overflow
data 09 ; overflow
data 09 ; mantissa
data 09
data 09
@ -875,13 +886,17 @@ normalizeRoundUp:
breq r0, r0, normalizeRoundUpLoop
normalizeRoundUpEnd:
cleq r0, r0, popWord
cleq r0, r0, popWord
cleq r0, r0, popWord
normalizeRoundUpEnd:
cleq r0, r0, popWord
cleq r0, r0, popWord
cleq r0, r0, popWord
; We might have ended up with a digit in the overflow
breq r0, r0, normalize
; Zero out the rounding digit
xor r0, r0
store fResult+11, r0
; We might have ended up with a digit in the overflow
breq r0, r0, normalize
normalizeRoundDown:
; Zero out the rounding digit