# See if the new Data Stack Offset should wrap. If so, set it to zero.
LDSP+0
IM_12 # Total of four stack entries (offsets: 0, 4, 8, 12).
- JSR>subtract
- TEST
- IM_12 # Address of PSW register.
- LOAD
- IM_2 # Negative bit in PSW
- AND
- BRZ>incrementstackindexreturn
+ BLE>incrementstackindexreturn
# Negative bit was set, so wrap to start of stack.
TEST
IM_0
# See if new Data Stack Offset should wrap, indicated by value < 0.
# If so, set it to 12 (offsets: 0, 4, 8, 12).
LDSP+0
- TEST
- IM_12 # Address of PSW register.
- LOAD
- IM_2 # Negative bit in PSW register.
- AND
- BRZ>decrementstackindexreturn
+ IM_0
+ BGE>decrementstackindexreturn
# Negative bit was set, so wrap to end of stack.
TEST
IM_12
WORD_38 # ASCII "'"
IM_1
ADD
- JSR>subtract
- BRZ>evalzerostackentrymatch
+ BEQ>evalzerostackentrymatch
# No match, return from subroutine
RTS
# Test for ASCII ','
WORD_44 # ASCII ','
- JSR>subtract
- BRZ>evalstacknavigationprevmatch
+ BEQ>evalstacknavigationprevmatch
# No match.
JMP>evalstacknavigationnexttest
evalstacknavigationnexttest
# Test for ASCII '.'
WORD_46 # ASCII '.'
- JSR>subtract
- BRZ>evalstacknavigationnextmatch
+ BEQ>evalstacknavigationnextmatch
# No match.
RTS
WORD_58 # ASCII ';'
IM_1
ADD
- JSR>subtract
- BRZ>evalnegatestackentrymatch
+ BEQ>evalnegatestackentrymatch
# No match, return from subroutine
RTS
IM_30
IM_13
ADD
- JSR>subtract
- BRZ>evalmathadditionmatch
+ BEQ>evalmathadditionmatch
# No match, return from subroutine
RTS
IM_30
IM_15
ADD
- JSR>subtract
- BRZ>evalmathsubtractionmatch
+ BEQ>evalmathsubtractionmatch
# No match, return from subroutine
RTS
IM_30
IM_12
ADD
- JSR>subtract
- BRZ>evalmathmultiplicationmatch
+ BEQ>evalmathmultiplicationmatch
# No match, return from subroutine
RTS
IM_30
IM_17
ADD
- JSR>subtract
- BRZ>evalmathdivisionmatch
+ BEQ>evalmathdivisionmatch
# No match, return from subroutine
RTS
JSR>subtract
# Copy and test negative result. This would indicate an ASCII character below '0'.
LDSP+0
- TEST
- IM_12 # Address of PSW register
- LOAD
- IM_2
- AND
- BRZ>isasciidigitcontinued
+ IM_0
+ BGE>isasciidigitcontinued
# The result was negative, so clean up stack and return false.
IM_1
STSP+0
SWAP
RTS
isasciidigitcontinued
- # Subtract another 10 and check for positive result. This indicates ASCII char > '9'.
- IM_10
+ # Subtract another 9 and check for positive result. This indicates ASCII char > '9'.
+ IM_9
SWAP
JSR>subtract
- TEST
- IM_12
- LOAD
- IM_2
- AND
- BRZ>isasciidigitfalse
+ BPL>isasciidigitfalse
# The result was true, so clean up stack and return true.
IM_0
SWAP
AND
BRZ>absolutevaluereturn
JSR>negate
-
absolutevaluereturn
SWAP
RTS
# Test for completion of multiplication algorithm (31 shifts).
LDSP+1 # Shift magnitude
- IM_30
- JSR>subtract
- BRZ>multiplycleanup
+ IM_31
+ BEQ>multiplycleanup
JMP>testbit
# Clean up the the stack after performing multiplication.
OR
# Check if Remainder >= Divisor
- LDSP+3 # Divisor
- LDSP+1 # Remainder
- JSR>subtract
- TEST
- IM_12 # Address of PSW register
- LOAD
- IM_2 # Bit for Negative Flag in PSW
- AND
- IM_2
- XOR
- BRZ>divisionsubloopend
+ LDSP+0 # Remainder
+ LDSP+4 # Divisor
+ BLT>divisionsubloopend
# If Remainder >= Divisor
# Copy operand to TOS
LDSP+1
# Verify that operand < 10
+ LDSP+0
IM_10
- LDSP+1
- JSR>subtract
- TEST # Set PSW according to difference.
- # Branch if non-negative:
- IM_12 # Address of PSW
- LOAD
- IM_2
- AND
- BRZ>itoahalt
+ BGE>itoahalt
# Verify that operand > -1
LDSP+0
- TEST # Set PSW according to operand.
- # Branch if negative:
- IM_12
- LOAD
- IM_2
- AND
- IM_2
- XOR
- BRZ>itoahalt # Branch if operand was negative.
+ BMI>itoahalt
# Convert the integer to its ASCII representation and return to caller.
WORD_48
ADD