On a dedicated breadboard I used two 74LS191 counter chips to create an 8-bit Stack Pointer for my Ben Eater inspired 8-bit breadboard CPU. Whereas the Program Counter uses 2 74LS161 chips, I wanted to be able to have it auto increment and decrement based on leveraging the existing SU (subtract) control signal and the new SPE (stack pointer enable) control signal I added. To accomplish this I had to expand to a 3rd microcontroller EEPROM to add SPI, SPO, and SPE control signal outputs (stack pointer in, stack pointer out, and stack pointer enable).
Where did strange things happen? First I made some wiring mistakes as well as microcode errors, which took about an hour to fully debug. Also, using the clock for the auto increment/decrement I would get 2 counts up or 2 counts down when incrementing or decrementing both while single stepping and running the clock normally; changing the trigger to be off the inverted clock signal fixed this for me.
To make initial use of the stack and for testing I added LDSP, PUSH, and POP instructions and their microcode to my implementation:
{ MI|CO, RO|II|CE, MI|SPO, AO|RI, SU|SPE, 0, 0, 0 }, // 0001 0000 - PUSH - Push Accumulator on Stack
{ MI|CO, RO|II|CE, SPE, MI|SPO, RO|AI, 0, 0, 0 }, // 0001 0001 - POP - Pop off Stack to Accumulator
{ MI|CO, RO|II|CE, MI|CO, RO|SPI|CE, 0, 0, 0, 0 }, // 0001 0010 - LDSP (2 byte) - Load Stack Pointer Immediate
You'll see that when pushing items on the stack I store the contents of the A register to where the stack is currently pointing then I decrement it to get it ready for the next push. For a pop I first increment the pointer then read from that memory location and store the results in A. Note: in the video I mistakenly say I decrement when popping when I'm actually incrementing.
Next task? I want to add JSR and RST such that I can call subroutines then to return from them. All that should require is a couple new lines of microcode table entries. Fingers crossed!
-Mark
Информация по комментариям в разработке