The stack calculator is a 4-bit calculator. It is meant to be used in a larger circuit that will handle timing and memory. It is not a processor since it does not contain a program counter or attempt to access memory on its own. Rather, it accepts inputs in particular sequences and gives outputs depending on the instructions provided.
The stack calculator consists of a 4-bit wide stack that is 8 entries deep. The thing that makes it a stack calculator is the fact that all operations are performed against this stack. The user will provide opcodes at every upwards tick of the clock cycle to instruct the machine on what to do next.
The stack calculator can also save 16 4-bit values using the
All opcodes are 4 bits long. Some opcodes accept one additional input that define the operation. Ops take at least 2 cycles to complete and at most 5 cycles.
Opcodes and operands are always 4-bits wide and are applied to the 4 input pins (pins 2-5) and need to be applied before the clock ticks up. In some cases they need to be held for more than one cycle for them to apply.
All input must be provided in a particular order. Below is a timing diagram that shows how to apply opcodes to the processor
Timing diagram CLK ___ ___ ___ ___ ___ ___ __/ \___/ \___/ \___/ \___/ \___/ \___ | | | | | | | | | | | | 1. ___________ ________________________________ _/ OP CODE \___/ next operation ... 2. _____________ _____________ ________________ _/ OP CODE \/ OPERAND \__/ next op... 3. _____________ _____________ ________ _/ OP CODE \/ OPERAND \__________/ ... wait 1 cycle LEGEND 1. 2-cycle opcode, no operands 2. 4-cycle opcode, 1 operand 3. 5-cycle opcode, 1 operand (PUSH)
The stack machine also features an output register that can be written to using the
RESET PIN - Please hold the reset pin high and tick the clock at least 4 cycles to reset the machine.
MODE PINS - The input pins 6 and 7 are the mode pin. They can be used to set the output pins to output specific things depending on their value:
The list opcodes are as follows:
The following diagram shows a simple test setup that can be used to test the stack calculator
VCC | __|__ pushbutton +----. .-------------+ | _|_ | schmitt \ / | trigger O | inverter | | __|__ +--> CLK OUT0 -----+ +--. .------------------> RST OUT1 -. | button +--------+---> IN0 . _|_ + +---> IN1 . \ / buffer + +---> IN2 . | + DIP +---> IN3 | + switch +---> MODE0 +--> 7 segment + +---> MODE1 | + +-- +--> LED bar array +--------+-- . . .
By using a schmitt trigger for debounce and an inverter, it is possible to perform a tick up with a specific DIP switch setting, allowing us to experiment with different kinds of inputs in sequence.
Using the DIP switch you can also change the MODE pins to debug your stack or display the output register contents.