From b534dfa24f97d29ca672db9c60e7558ba2bf328b Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Wed, 2 Jan 2019 01:49:13 -0800 Subject: [PATCH] Updated BRZs in calculator to use new branch types. --- software/4func_calculator/README.md | 2 +- software/4func_calculator/calc.asm | 100 +++++++--------------------- 2 files changed, 25 insertions(+), 77 deletions(-) diff --git a/software/4func_calculator/README.md b/software/4func_calculator/README.md index 57ef602..f17f3fb 100644 --- a/software/4func_calculator/README.md +++ b/software/4func_calculator/README.md @@ -7,7 +7,7 @@ assembly. Compatibility ============= -The calculator is compatible with `nedasm` v2 and `nedsim` v4. +The calculator is compatible with `nedasm` v3 and `nedsim` v4. Instructions ============ diff --git a/software/4func_calculator/calc.asm b/software/4func_calculator/calc.asm index c3aeac5..64a3fd8 100644 --- a/software/4func_calculator/calc.asm +++ b/software/4func_calculator/calc.asm @@ -117,13 +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). - 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 @@ -151,12 +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 - 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 @@ -349,8 +339,7 @@ evalzerostackentry WORD_38 # ASCII "'" IM_1 ADD - JSR>subtract - BRZ>evalzerostackentrymatch + BEQ>evalzerostackentrymatch # No match, return from subroutine RTS @@ -393,8 +382,7 @@ evalstacknavigation # Test for ASCII ',' WORD_44 # ASCII ',' - JSR>subtract - BRZ>evalstacknavigationprevmatch + BEQ>evalstacknavigationprevmatch # No match. JMP>evalstacknavigationnexttest @@ -422,8 +410,7 @@ evalstacknavigation evalstacknavigationnexttest # Test for ASCII '.' WORD_46 # ASCII '.' - JSR>subtract - BRZ>evalstacknavigationnextmatch + BEQ>evalstacknavigationnextmatch # No match. RTS @@ -460,8 +447,7 @@ evalnegatestackentry WORD_58 # ASCII ';' IM_1 ADD - JSR>subtract - BRZ>evalnegatestackentrymatch + BEQ>evalnegatestackentrymatch # No match, return from subroutine RTS @@ -508,8 +494,7 @@ evalmathaddition IM_30 IM_13 ADD - JSR>subtract - BRZ>evalmathadditionmatch + BEQ>evalmathadditionmatch # No match, return from subroutine RTS @@ -575,8 +560,7 @@ evalmathsubtraction IM_30 IM_15 ADD - JSR>subtract - BRZ>evalmathsubtractionmatch + BEQ>evalmathsubtractionmatch # No match, return from subroutine RTS @@ -642,8 +626,7 @@ evalmathmultiplication IM_30 IM_12 ADD - JSR>subtract - BRZ>evalmathmultiplicationmatch + BEQ>evalmathmultiplicationmatch # No match, return from subroutine RTS @@ -710,8 +693,7 @@ evalmathdivision IM_30 IM_17 ADD - JSR>subtract - BRZ>evalmathdivisionmatch + BEQ>evalmathdivisionmatch # No match, return from subroutine RTS @@ -839,28 +821,19 @@ isasciidigit 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 @@ -942,7 +915,6 @@ absolutevalue AND BRZ>absolutevaluereturn JSR>negate - absolutevaluereturn SWAP RTS @@ -1025,9 +997,8 @@ multiply # 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. @@ -1137,17 +1108,9 @@ divide 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 @@ -1274,27 +1237,12 @@ itoa # 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 -- 2.20.1