Updated BRZs in calculator to use new branch types.
[ned1] / software / 4func_calculator / calc.asm
index 4386392..64a3fd8 100644 (file)
@@ -88,7 +88,6 @@ calcinit
 
         # Check for loop termination
         LDSP+0
 
         # Check for loop termination
         LDSP+0
-        TEST
         BRZ>calcinitzeroloopend
             JMP>calcinitzeroloop
 
         BRZ>calcinitzeroloopend
             JMP>calcinitzeroloop
 
@@ -118,14 +117,7 @@ incrementstackindex
     # 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).
     # 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
-    TEST
-    BRZ>incrementstackindexreturn
+    BLE>incrementstackindexreturn
         # Negative bit was set, so wrap to start of stack.
         TEST
         IM_0
         # Negative bit was set, so wrap to start of stack.
         TEST
         IM_0
@@ -153,13 +145,8 @@ decrementstackindex
     # 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
     # 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
-    TEST
-    BRZ>decrementstackindexreturn
+    IM_0
+    BGE>decrementstackindexreturn
         # Negative bit was set, so wrap to end of stack.
         TEST
         IM_12
         # Negative bit was set, so wrap to end of stack.
         TEST
         IM_12
@@ -240,7 +227,6 @@ printbinaryinteger
 
     # First check if the number is zero and print a single zero if true.
     LDSP+0
 
     # First check if the number is zero and print a single zero if true.
     LDSP+0
-    TEST
     BRZ>printbinaryintegerloopend
 
     # Repeatedly divide by ten and push each digit onto the stack in ASCII.
     BRZ>printbinaryintegerloopend
 
     # Repeatedly divide by ten and push each digit onto the stack in ASCII.
@@ -248,7 +234,6 @@ printbinaryinteger
 
     # Verify Integer still has digits to print (i.e. Integer != 0)
     LDSP+0
 
     # Verify Integer still has digits to print (i.e. Integer != 0)
     LDSP+0
-    TEST
     BRZ>printbinaryintegerloopend
 
         # Extract the least significant digit.
     BRZ>printbinaryintegerloopend
 
         # Extract the least significant digit.
@@ -282,7 +267,6 @@ printbinaryinteger
     #   Sign flag (nonzero for negative result, 0 for positive result)
 
     # Push sign onto stack as ASCII character.
     #   Sign flag (nonzero for negative result, 0 for positive result)
 
     # Push sign onto stack as ASCII character.
-    TEST
     BRZ>printbinaryintegerpositive
 
         # Add ASCII '-' sign to stack
     BRZ>printbinaryintegerpositive
 
         # Add ASCII '-' sign to stack
@@ -355,9 +339,7 @@ evalzerostackentry
     WORD_38 # ASCII "'"
     IM_1
     ADD
     WORD_38 # ASCII "'"
     IM_1
     ADD
-    JSR>subtract
-    TEST
-    BRZ>evalzerostackentrymatch
+    BEQ>evalzerostackentrymatch
 
         # No match, return from subroutine
         RTS
 
         # No match, return from subroutine
         RTS
@@ -400,9 +382,7 @@ evalstacknavigation
 
     # Test for ASCII ','
     WORD_44 # ASCII ','
 
     # Test for ASCII ','
     WORD_44 # ASCII ','
-    JSR>subtract
-    TEST
-    BRZ>evalstacknavigationprevmatch
+    BEQ>evalstacknavigationprevmatch
 
         # No match.
         JMP>evalstacknavigationnexttest
 
         # No match.
         JMP>evalstacknavigationnexttest
@@ -430,9 +410,7 @@ evalstacknavigation
     evalstacknavigationnexttest
     # Test for ASCII '.'
     WORD_46 # ASCII '.'
     evalstacknavigationnexttest
     # Test for ASCII '.'
     WORD_46 # ASCII '.'
-    JSR>subtract
-    TEST
-    BRZ>evalstacknavigationnextmatch
+    BEQ>evalstacknavigationnextmatch
 
         # No match.
         RTS
 
         # No match.
         RTS
@@ -469,9 +447,7 @@ evalnegatestackentry
     WORD_58 # ASCII ';'
     IM_1
     ADD
     WORD_58 # ASCII ';'
     IM_1
     ADD
-    JSR>subtract
-    TEST
-    BRZ>evalnegatestackentrymatch
+    BEQ>evalnegatestackentrymatch
 
         # No match, return from subroutine
         RTS
 
         # No match, return from subroutine
         RTS
@@ -518,9 +494,7 @@ evalmathaddition
     IM_30
     IM_13
     ADD
     IM_30
     IM_13
     ADD
-    JSR>subtract
-    TEST
-    BRZ>evalmathadditionmatch
+    BEQ>evalmathadditionmatch
 
         # No match, return from subroutine
         RTS
 
         # No match, return from subroutine
         RTS
@@ -586,9 +560,7 @@ evalmathsubtraction
     IM_30
     IM_15
     ADD
     IM_30
     IM_15
     ADD
-    JSR>subtract
-    TEST
-    BRZ>evalmathsubtractionmatch
+    BEQ>evalmathsubtractionmatch
 
         # No match, return from subroutine
         RTS
 
         # No match, return from subroutine
         RTS
@@ -654,9 +626,7 @@ evalmathmultiplication
     IM_30
     IM_12
     ADD
     IM_30
     IM_12
     ADD
-    JSR>subtract
-    TEST
-    BRZ>evalmathmultiplicationmatch
+    BEQ>evalmathmultiplicationmatch
 
         # No match, return from subroutine
         RTS
 
         # No match, return from subroutine
         RTS
@@ -723,9 +693,7 @@ evalmathdivision
     IM_30
     IM_17
     ADD
     IM_30
     IM_17
     ADD
-    JSR>subtract
-    TEST
-    BRZ>evalmathdivisionmatch
+    BEQ>evalmathdivisionmatch
 
         # No match, return from subroutine
         RTS
 
         # No match, return from subroutine
         RTS
@@ -801,7 +769,6 @@ evalasciidigit
 
     # Test for ASCII digit.
     JSR>isasciidigit
 
     # Test for ASCII digit.
     JSR>isasciidigit
-    TEST
     BRZ>evalasciidigitmatch
 
         # No match, return from subroutine
     BRZ>evalasciidigitmatch
 
         # No match, return from subroutine
@@ -854,30 +821,19 @@ isasciidigit
     JSR>subtract
     # Copy and test negative result. This would indicate an ASCII character below '0'.
     LDSP+0
     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
-    TEST
-    BRZ>isasciidigitcontinued
+    IM_0
+    BGE>isasciidigitcontinued
         # The result was negative, so clean up stack and return false.
         IM_1
         STSP+0
         SWAP
         RTS
     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
     SWAP
     JSR>subtract
-    TEST
-    IM_12
-    LOAD
-    IM_2
-    AND
-    TEST
-    BRZ>isasciidigitfalse
+    BPL>isasciidigitfalse
         # The result was true, so clean up stack and return true.
         IM_0
         SWAP
         # The result was true, so clean up stack and return true.
         IM_0
         SWAP
@@ -957,10 +913,8 @@ absolutevalue
     IM_4
     LOAD
     AND
     IM_4
     LOAD
     AND
-    TEST
     BRZ>absolutevaluereturn
         JSR>negate
     BRZ>absolutevaluereturn
         JSR>negate
-
     absolutevaluereturn
         SWAP
         RTS
     absolutevaluereturn
         SWAP
         RTS
@@ -1024,7 +978,6 @@ multiply
         SHIFT
         IM_1
         AND
         SHIFT
         IM_1
         AND
-        TEST
         BRZ>skipadd
             # If indicated by a 1 bit, shift and add first operand to result.
             LDSP+3          # X Operand
         BRZ>skipadd
             # If indicated by a 1 bit, shift and add first operand to result.
             LDSP+3          # X Operand
@@ -1044,10 +997,8 @@ multiply
 
     # Test for completion of multiplication algorithm (31 shifts).
     LDSP+1                  # Shift magnitude
 
     # Test for completion of multiplication algorithm (31 shifts).
     LDSP+1                  # Shift magnitude
-    IM_30
-    JSR>subtract
-    TEST
-    BRZ>multiplycleanup
+    IM_31
+    BEQ>multiplycleanup
         JMP>testbit
 
     # Clean up the the stack after performing multiplication.
         JMP>testbit
 
     # Clean up the the stack after performing multiplication.
@@ -1064,7 +1015,6 @@ multiply
     # Set the sign of the product.
     applysign
         SWAP
     # Set the sign of the product.
     applysign
         SWAP
-        TEST
         BRZ>multiplyreturn
             JSR>negate
 
         BRZ>multiplyreturn
             JSR>negate
 
@@ -1100,7 +1050,6 @@ divide
 
     # Check for zero divisor
     LDSP+0
 
     # Check for zero divisor
     LDSP+0
-    TEST
     BRZ>divideexception
 
     # Generate a sign flag and store it behind the operands.
     BRZ>divideexception
 
     # Generate a sign flag and store it behind the operands.
@@ -1139,7 +1088,6 @@ divide
         LDSP+2 # Cycle Counter
         IM_1
         ADD
         LDSP+2 # Cycle Counter
         IM_1
         ADD
-        TEST
         BRZ>divisionloopend
 
             # While Cycle Counter >= 0
         BRZ>divisionloopend
 
             # While Cycle Counter >= 0
@@ -1160,18 +1108,9 @@ divide
             OR
     
             # Check if Remainder >= Divisor
             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
-            TEST
-            BRZ>divisionsubloopend
+            LDSP+0 # Remainder
+            LDSP+4 # Divisor
+            BLT>divisionsubloopend
 
                 # If Remainder >= Divisor
 
 
                 # If Remainder >= Divisor
 
@@ -1217,7 +1156,6 @@ divide
 
     # Set sign of results.
     LDSP+2 # Sign flag
 
     # Set sign of results.
     LDSP+2 # Sign flag
-    TEST
     BRZ>divisioncleanup
         JSR>negate
         SWAP
     BRZ>divisioncleanup
         JSR>negate
         SWAP
@@ -1299,29 +1237,12 @@ itoa
     # Copy operand to TOS
     LDSP+1
     # Verify that operand < 10
     # Copy operand to TOS
     LDSP+1
     # Verify that operand < 10
+    LDSP+0
     IM_10
     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
-    TEST
-    BRZ>itoahalt
+    BGE>itoahalt
     # Verify that operand > -1
     LDSP+0
     # Verify that operand > -1
     LDSP+0
-    TEST # Set PSW according to operand.
-    # Branch if negative:
-    IM_12
-    LOAD
-    IM_2
-    AND
-    IM_2
-    XOR
-    TEST
-    BRZ>itoahalt # Branch if operand was negative.
+    BMI>itoahalt
     # Convert the integer to its ASCII representation and return to caller.
     WORD_48
     ADD
     # Convert the integer to its ASCII representation and return to caller.
     WORD_48
     ADD
@@ -1349,7 +1270,6 @@ putchar
     putcharloop
         LDSP+0
         LOAD
     putcharloop
         LDSP+0
         LOAD
-        TEST
         BRZ>putcharloop
     TEST # Drop XCSR from stack
     SWAP
         BRZ>putcharloop
     TEST # Drop XCSR from stack
     SWAP
@@ -1373,7 +1293,6 @@ getchar
     getcharloop
         LDSP+0
         LOAD
     getcharloop
         LDSP+0
         LOAD
-        TEST
         BRZ>getcharloop
     LDSP+1
     LOAD
         BRZ>getcharloop
     LDSP+1
     LOAD
@@ -1396,6 +1315,7 @@ printstring
 #   Return PC <-- TOS
 ##########################################################################################
     SWAP
 #   Return PC <-- TOS
 ##########################################################################################
     SWAP
+    LDSP+0
     BRZ>printstringreturn
     JSR>putchar
     JMP>printstring
     BRZ>printstringreturn
     JSR>putchar
     JMP>printstring