Changed BRZ behavior to chomp a test word from stack instead of checking PSW_Z bit.
[ned1] / software / 4func_calculator / calc.asm
index 4386392..c3aeac5 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
 
@@ -124,7 +123,6 @@ incrementstackindex
     LOAD
     IM_2        # Negative bit in PSW
     AND
     LOAD
     IM_2        # Negative bit in PSW
     AND
-    TEST
     BRZ>incrementstackindexreturn
         # Negative bit was set, so wrap to start of stack.
         TEST
     BRZ>incrementstackindexreturn
         # Negative bit was set, so wrap to start of stack.
         TEST
@@ -158,7 +156,6 @@ decrementstackindex
     LOAD
     IM_2    # Negative bit in PSW register.
     AND
     LOAD
     IM_2    # Negative bit in PSW register.
     AND
-    TEST
     BRZ>decrementstackindexreturn
         # Negative bit was set, so wrap to end of stack.
         TEST
     BRZ>decrementstackindexreturn
         # Negative bit was set, so wrap to end of stack.
         TEST
@@ -240,7 +237,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 +244,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 +277,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
@@ -356,7 +350,6 @@ evalzerostackentry
     IM_1
     ADD
     JSR>subtract
     IM_1
     ADD
     JSR>subtract
-    TEST
     BRZ>evalzerostackentrymatch
 
         # No match, return from subroutine
     BRZ>evalzerostackentrymatch
 
         # No match, return from subroutine
@@ -401,7 +394,6 @@ evalstacknavigation
     # Test for ASCII ','
     WORD_44 # ASCII ','
     JSR>subtract
     # Test for ASCII ','
     WORD_44 # ASCII ','
     JSR>subtract
-    TEST
     BRZ>evalstacknavigationprevmatch
 
         # No match.
     BRZ>evalstacknavigationprevmatch
 
         # No match.
@@ -431,7 +423,6 @@ evalstacknavigation
     # Test for ASCII '.'
     WORD_46 # ASCII '.'
     JSR>subtract
     # Test for ASCII '.'
     WORD_46 # ASCII '.'
     JSR>subtract
-    TEST
     BRZ>evalstacknavigationnextmatch
 
         # No match.
     BRZ>evalstacknavigationnextmatch
 
         # No match.
@@ -470,7 +461,6 @@ evalnegatestackentry
     IM_1
     ADD
     JSR>subtract
     IM_1
     ADD
     JSR>subtract
-    TEST
     BRZ>evalnegatestackentrymatch
 
         # No match, return from subroutine
     BRZ>evalnegatestackentrymatch
 
         # No match, return from subroutine
@@ -519,7 +509,6 @@ evalmathaddition
     IM_13
     ADD
     JSR>subtract
     IM_13
     ADD
     JSR>subtract
-    TEST
     BRZ>evalmathadditionmatch
 
         # No match, return from subroutine
     BRZ>evalmathadditionmatch
 
         # No match, return from subroutine
@@ -587,7 +576,6 @@ evalmathsubtraction
     IM_15
     ADD
     JSR>subtract
     IM_15
     ADD
     JSR>subtract
-    TEST
     BRZ>evalmathsubtractionmatch
 
         # No match, return from subroutine
     BRZ>evalmathsubtractionmatch
 
         # No match, return from subroutine
@@ -655,7 +643,6 @@ evalmathmultiplication
     IM_12
     ADD
     JSR>subtract
     IM_12
     ADD
     JSR>subtract
-    TEST
     BRZ>evalmathmultiplicationmatch
 
         # No match, return from subroutine
     BRZ>evalmathmultiplicationmatch
 
         # No match, return from subroutine
@@ -724,7 +711,6 @@ evalmathdivision
     IM_17
     ADD
     JSR>subtract
     IM_17
     ADD
     JSR>subtract
-    TEST
     BRZ>evalmathdivisionmatch
 
         # No match, return from subroutine
     BRZ>evalmathdivisionmatch
 
         # No match, return from subroutine
@@ -801,7 +787,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
@@ -859,7 +844,6 @@ isasciidigit
     LOAD
     IM_2
     AND
     LOAD
     IM_2
     AND
-    TEST
     BRZ>isasciidigitcontinued
         # The result was negative, so clean up stack and return false.
         IM_1
     BRZ>isasciidigitcontinued
         # The result was negative, so clean up stack and return false.
         IM_1
@@ -876,7 +860,6 @@ isasciidigit
     LOAD
     IM_2
     AND
     LOAD
     IM_2
     AND
-    TEST
     BRZ>isasciidigitfalse
         # The result was true, so clean up stack and return true.
         IM_0
     BRZ>isasciidigitfalse
         # The result was true, so clean up stack and return true.
         IM_0
@@ -957,7 +940,6 @@ absolutevalue
     IM_4
     LOAD
     AND
     IM_4
     LOAD
     AND
-    TEST
     BRZ>absolutevaluereturn
         JSR>negate
 
     BRZ>absolutevaluereturn
         JSR>negate
 
@@ -1024,7 +1006,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
@@ -1046,7 +1027,6 @@ multiply
     LDSP+1                  # Shift magnitude
     IM_30
     JSR>subtract
     LDSP+1                  # Shift magnitude
     IM_30
     JSR>subtract
-    TEST
     BRZ>multiplycleanup
         JMP>testbit
 
     BRZ>multiplycleanup
         JMP>testbit
 
@@ -1064,7 +1044,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 +1079,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 +1117,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
@@ -1170,7 +1147,6 @@ divide
             AND
             IM_2
             XOR
             AND
             IM_2
             XOR
-            TEST
             BRZ>divisionsubloopend
 
                 # If Remainder >= Divisor
             BRZ>divisionsubloopend
 
                 # If Remainder >= Divisor
@@ -1217,7 +1193,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
@@ -1308,7 +1283,6 @@ itoa
     LOAD
     IM_2
     AND
     LOAD
     IM_2
     AND
-    TEST
     BRZ>itoahalt
     # Verify that operand > -1
     LDSP+0
     BRZ>itoahalt
     # Verify that operand > -1
     LDSP+0
@@ -1320,7 +1294,6 @@ itoa
     AND
     IM_2
     XOR
     AND
     IM_2
     XOR
-    TEST
     BRZ>itoahalt # Branch if operand was negative.
     # Convert the integer to its ASCII representation and return to caller.
     WORD_48
     BRZ>itoahalt # Branch if operand was negative.
     # Convert the integer to its ASCII representation and return to caller.
     WORD_48
@@ -1349,7 +1322,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 +1345,6 @@ getchar
     getcharloop
         LDSP+0
         LOAD
     getcharloop
         LDSP+0
         LOAD
-        TEST
         BRZ>getcharloop
     LDSP+1
     LOAD
         BRZ>getcharloop
     LDSP+1
     LOAD
@@ -1396,6 +1367,7 @@ printstring
 #   Return PC <-- TOS
 ##########################################################################################
     SWAP
 #   Return PC <-- TOS
 ##########################################################################################
     SWAP
+    LDSP+0
     BRZ>printstringreturn
     JSR>putchar
     JMP>printstring
     BRZ>printstringreturn
     JSR>putchar
     JMP>printstring