From: Aaron Taylor Date: Mon, 31 Dec 2018 11:27:26 +0000 (-0800) Subject: Changed BRZ behavior to chomp a test word from stack instead of checking PSW_Z bit. X-Git-Url: http://git.subgeniuskitty.com/ned1/.git/commitdiff_plain/418f3fc7602ff5e2dad5bc6c39b283d028be506c Changed BRZ behavior to chomp a test word from stack instead of checking PSW_Z bit. This eliminates the need for a preceding TEST syllable. The calculator has been updated. --- diff --git a/docs/architecture_manual.md b/docs/architecture_manual.md index 262c179..e2a7de3 100644 --- a/docs/architecture_manual.md +++ b/docs/architecture_manual.md @@ -14,7 +14,7 @@ Overview * Explicitly no MMU, just a flat, shared memory space. Think threads, not processes. -Version: 1 +Version: 2 Instruction Word Formats ------------------------ @@ -64,7 +64,7 @@ Syllables are defined as follows. | 000100 | SHIFT | Pop TOS & NOS. Shift NOS by TOS bits to the left/right. | | 000101 | CMPSWP | Compare-and-swap with ptr, old_val & new_val on stack. | | 000110 | TEST | Pop TOS and set PSW according to value. | -| 000111 | BRZ | Pop TOS. If PSW_Z==1, then set PC to popped value. | +| 000111 | BRZ | Pop TOS & NOS. If NOS==0, then set PC to TOS value. | | 000010 | LOAD | Pop address from TOS, dereference and store to TOS. | | 000011 | STORE | Pop address from TOS, pop data from NOS, deref and store. | | 000001 | NOP | Do nothing. | diff --git a/docs/compat_matrix.md b/docs/compat_matrix.md index eb6cb94..5faf44f 100644 --- a/docs/compat_matrix.md +++ b/docs/compat_matrix.md @@ -12,3 +12,4 @@ Compatibility Matrix | 1 | 1 | 1 | 1 | 1 | | 2 | 2 | 2 | . | . | | 3 | . | . | . | . | +| 4 | . | . | 2 | 2 | diff --git a/docs/instruction_reference.md b/docs/instruction_reference.md index d8bc473..690623d 100644 --- a/docs/instruction_reference.md +++ b/docs/instruction_reference.md @@ -4,7 +4,7 @@ NED - Instruction Reference Overview -------- -Version: 1 +Version: 2 Format A - Word --------------- @@ -211,10 +211,9 @@ Description: Pops TOS and sets PSW flags accordingly. | BRZ | 0 | 0 | 0 | 1 | 1 | 1 | +----------+---+---+---+---+---+---+ -Operation: PC = TOS if PSW_Z = 0 +Operation: PC = TOS if NOS = 0 Indicators: None -Description: Pops TOS. If PSW_Z = 0, loads value in to PC, pushing old PC on to - TOS. +Description: Pops TOS and NOS. If NOS = 0, loads TOS value in to PC. -------------------------------------------------------------------------------- diff --git a/nedsim/nedsim.c b/nedsim/nedsim.c index aa9b7c4..b88328b 100644 --- a/nedsim/nedsim.c +++ b/nedsim/nedsim.c @@ -18,7 +18,7 @@ #include "../common/a.out.h" -#define VERSION 3 +#define VERSION 4 /* Bytes per word. */ #define BPW 4 @@ -437,7 +437,8 @@ void ned_instruction_brz(struct NEDstate * state) { uint32_t new_pc = stack_pop(state->active_thread); - if (state->active_thread->psw->zero == true) { + uint32_t test_word = stack_pop(state->active_thread); + if (test_word == 0) { state->active_thread->pc = new_pc; /* TODO: Find better way to communicate we're skipping ahead to the next word. */ state->active_thread->sc = 4; diff --git a/software/4func_calculator/calc.asm b/software/4func_calculator/calc.asm index 4386392..c3aeac5 100644 --- a/software/4func_calculator/calc.asm +++ b/software/4func_calculator/calc.asm @@ -88,7 +88,6 @@ calcinit # Check for loop termination LDSP+0 - TEST BRZ>calcinitzeroloopend JMP>calcinitzeroloop @@ -124,7 +123,6 @@ incrementstackindex LOAD IM_2 # Negative bit in PSW AND - 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 - 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 - TEST 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 - TEST 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. - TEST BRZ>printbinaryintegerpositive # Add ASCII '-' sign to stack @@ -356,7 +350,6 @@ evalzerostackentry IM_1 ADD JSR>subtract - TEST BRZ>evalzerostackentrymatch # No match, return from subroutine @@ -401,7 +394,6 @@ evalstacknavigation # Test for ASCII ',' WORD_44 # ASCII ',' JSR>subtract - TEST BRZ>evalstacknavigationprevmatch # No match. @@ -431,7 +423,6 @@ evalstacknavigation # Test for ASCII '.' WORD_46 # ASCII '.' JSR>subtract - TEST BRZ>evalstacknavigationnextmatch # No match. @@ -470,7 +461,6 @@ evalnegatestackentry IM_1 ADD JSR>subtract - TEST BRZ>evalnegatestackentrymatch # No match, return from subroutine @@ -519,7 +509,6 @@ evalmathaddition IM_13 ADD JSR>subtract - TEST BRZ>evalmathadditionmatch # No match, return from subroutine @@ -587,7 +576,6 @@ evalmathsubtraction IM_15 ADD JSR>subtract - TEST BRZ>evalmathsubtractionmatch # No match, return from subroutine @@ -655,7 +643,6 @@ evalmathmultiplication IM_12 ADD JSR>subtract - TEST BRZ>evalmathmultiplicationmatch # No match, return from subroutine @@ -724,7 +711,6 @@ evalmathdivision IM_17 ADD JSR>subtract - TEST BRZ>evalmathdivisionmatch # No match, return from subroutine @@ -801,7 +787,6 @@ evalasciidigit # Test for ASCII digit. JSR>isasciidigit - TEST BRZ>evalasciidigitmatch # No match, return from subroutine @@ -859,7 +844,6 @@ isasciidigit LOAD IM_2 AND - TEST BRZ>isasciidigitcontinued # The result was negative, so clean up stack and return false. IM_1 @@ -876,7 +860,6 @@ isasciidigit LOAD IM_2 AND - TEST BRZ>isasciidigitfalse # The result was true, so clean up stack and return true. IM_0 @@ -957,7 +940,6 @@ absolutevalue IM_4 LOAD AND - TEST BRZ>absolutevaluereturn JSR>negate @@ -1024,7 +1006,6 @@ multiply SHIFT IM_1 AND - TEST 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 - TEST BRZ>multiplycleanup JMP>testbit @@ -1064,7 +1044,6 @@ multiply # Set the sign of the product. applysign SWAP - TEST BRZ>multiplyreturn JSR>negate @@ -1100,7 +1079,6 @@ divide # Check for zero divisor LDSP+0 - TEST BRZ>divideexception # Generate a sign flag and store it behind the operands. @@ -1139,7 +1117,6 @@ divide LDSP+2 # Cycle Counter IM_1 ADD - TEST BRZ>divisionloopend # While Cycle Counter >= 0 @@ -1170,7 +1147,6 @@ divide AND IM_2 XOR - TEST BRZ>divisionsubloopend # If Remainder >= Divisor @@ -1217,7 +1193,6 @@ divide # Set sign of results. LDSP+2 # Sign flag - TEST BRZ>divisioncleanup JSR>negate SWAP @@ -1308,7 +1283,6 @@ itoa LOAD IM_2 AND - TEST BRZ>itoahalt # Verify that operand > -1 LDSP+0 @@ -1320,7 +1294,6 @@ itoa 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 @@ -1349,7 +1322,6 @@ putchar putcharloop LDSP+0 LOAD - TEST BRZ>putcharloop TEST # Drop XCSR from stack SWAP @@ -1373,7 +1345,6 @@ getchar getcharloop LDSP+0 LOAD - TEST BRZ>getcharloop LDSP+1 LOAD @@ -1396,6 +1367,7 @@ printstring # Return PC <-- TOS ########################################################################################## SWAP + LDSP+0 BRZ>printstringreturn JSR>putchar JMP>printstring