This eliminates the need for a preceding TEST syllable. The calculator has been updated.
* Explicitly no MMU, just a flat, shared memory space. Think threads, not
processes.
* Explicitly no MMU, just a flat, shared memory space. Think threads, not
processes.
Instruction Word Formats
------------------------
Instruction Word Formats
------------------------
| 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. |
| 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. |
| 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. |
| 1 | 1 | 1 | 1 | 1 |
| 2 | 2 | 2 | . | . |
| 3 | . | . | . | . |
| 1 | 1 | 1 | 1 | 1 |
| 2 | 2 | 2 | . | . |
| 3 | . | . | . | . |
Format A - Word
---------------
Format A - Word
---------------
| BRZ | 0 | 0 | 0 | 1 | 1 | 1 |
+----------+---+---+---+---+---+---+
| BRZ | 0 | 0 | 0 | 1 | 1 | 1 |
+----------+---+---+---+---+---+---+
-Operation: PC = TOS if PSW_Z = 0
+Operation: PC = TOS if NOS = 0
-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.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
#include "../common/a.out.h"
#include "../common/a.out.h"
/* Bytes per word. */
#define BPW 4
/* Bytes per word. */
#define BPW 4
ned_instruction_brz(struct NEDstate * state)
{
uint32_t new_pc = stack_pop(state->active_thread);
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;
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;
# Check for loop termination
LDSP+0
# Check for loop termination
LDSP+0
BRZ>calcinitzeroloopend
JMP>calcinitzeroloop
BRZ>calcinitzeroloopend
JMP>calcinitzeroloop
LOAD
IM_2 # Negative bit in PSW
AND
LOAD
IM_2 # Negative bit in PSW
AND
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
LOAD
IM_2 # Negative bit in PSW register.
AND
LOAD
IM_2 # Negative bit in PSW register.
AND
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
# 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
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.
# 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
BRZ>printbinaryintegerloopend
# Extract the least significant digit.
BRZ>printbinaryintegerloopend
# Extract the least significant digit.
# 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.
BRZ>printbinaryintegerpositive
# Add ASCII '-' sign to stack
BRZ>printbinaryintegerpositive
# Add ASCII '-' sign to stack
BRZ>evalzerostackentrymatch
# No match, return from subroutine
BRZ>evalzerostackentrymatch
# No match, return from subroutine
# Test for ASCII ','
WORD_44 # ASCII ','
JSR>subtract
# Test for ASCII ','
WORD_44 # ASCII ','
JSR>subtract
BRZ>evalstacknavigationprevmatch
# No match.
BRZ>evalstacknavigationprevmatch
# No match.
# Test for ASCII '.'
WORD_46 # ASCII '.'
JSR>subtract
# Test for ASCII '.'
WORD_46 # ASCII '.'
JSR>subtract
BRZ>evalstacknavigationnextmatch
# No match.
BRZ>evalstacknavigationnextmatch
# No match.
BRZ>evalnegatestackentrymatch
# No match, return from subroutine
BRZ>evalnegatestackentrymatch
# No match, return from subroutine
BRZ>evalmathadditionmatch
# No match, return from subroutine
BRZ>evalmathadditionmatch
# No match, return from subroutine
BRZ>evalmathsubtractionmatch
# No match, return from subroutine
BRZ>evalmathsubtractionmatch
# No match, return from subroutine
BRZ>evalmathmultiplicationmatch
# No match, return from subroutine
BRZ>evalmathmultiplicationmatch
# No match, return from subroutine
BRZ>evalmathdivisionmatch
# No match, return from subroutine
BRZ>evalmathdivisionmatch
# No match, return from subroutine
# Test for ASCII digit.
JSR>isasciidigit
# Test for ASCII digit.
JSR>isasciidigit
BRZ>evalasciidigitmatch
# No match, return from subroutine
BRZ>evalasciidigitmatch
# No match, return from subroutine
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
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
BRZ>absolutevaluereturn
JSR>negate
BRZ>absolutevaluereturn
JSR>negate
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
LDSP+1 # Shift magnitude
IM_30
JSR>subtract
LDSP+1 # Shift magnitude
IM_30
JSR>subtract
BRZ>multiplycleanup
JMP>testbit
BRZ>multiplycleanup
JMP>testbit
# Set the sign of the product.
applysign
SWAP
# Set the sign of the product.
applysign
SWAP
BRZ>multiplyreturn
JSR>negate
BRZ>multiplyreturn
JSR>negate
# Check for zero divisor
LDSP+0
# Check for zero divisor
LDSP+0
BRZ>divideexception
# Generate a sign flag and store it behind the operands.
BRZ>divideexception
# Generate a sign flag and store it behind the operands.
LDSP+2 # Cycle Counter
IM_1
ADD
LDSP+2 # Cycle Counter
IM_1
ADD
BRZ>divisionloopend
# While Cycle Counter >= 0
BRZ>divisionloopend
# While Cycle Counter >= 0
BRZ>divisionsubloopend
# If Remainder >= Divisor
BRZ>divisionsubloopend
# If Remainder >= Divisor
# Set sign of results.
LDSP+2 # Sign flag
# Set sign of results.
LDSP+2 # Sign flag
BRZ>divisioncleanup
JSR>negate
SWAP
BRZ>divisioncleanup
JSR>negate
SWAP
BRZ>itoahalt
# Verify that operand > -1
LDSP+0
BRZ>itoahalt
# Verify that operand > -1
LDSP+0
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
BRZ>putcharloop
TEST # Drop XCSR from stack
SWAP
BRZ>putcharloop
TEST # Drop XCSR from stack
SWAP
BRZ>getcharloop
LDSP+1
LOAD
BRZ>getcharloop
LDSP+1
LOAD
# Return PC <-- TOS
##########################################################################################
SWAP
# Return PC <-- TOS
##########################################################################################
SWAP
BRZ>printstringreturn
JSR>putchar
JMP>printstring
BRZ>printstringreturn
JSR>putchar
JMP>printstring