Close

I thought I was done with instructions for now

A project log for 8 Bit Breadboard CPU

A home-brew 8 bit Microprocessor built on a breadboard 64K Address Space, IRQ, and DMA 16 Bit Stack Pointer, 4 8 bit Registers or 2 16 bit

2-zons2-Zons 12/12/2018 at 05:173 Comments

Going over them one final time with advice from @roelh.  I've updated them to show which are 16 bit and which are 8 bit.  I've removed the XNR instruction, although I thought it was a good way to set a byte to FF, like the status register.  Used the free'd up codes to add the opposite jump's JNC, JNZ, JNM, and some XY stack addressing to the ADD and SUB commands.

https://docs.google.com/spreadsheets/d/1kbxYGDeIOszgvjPYRdes-bELOBlojT_tjxe_RD9MVUQ/edit?usp=sharing

Going through this I'm questioning how I have the XY stack instructions currently.  If it is being used as a stack that grows down in memory (starting at a high address and growing toward 0000h) then any time it is the destination it should be pre decremented.  This way it will move to it's new address then store, then it will hold the address of the last byte it stored.  When reading from the stack, or popping, it should post increment, so that it moves to the location where the next byte will be stored, and it will always be pointing to valid data (unless you hit bottom of the stack).

Is there something wrong with my thinking?  If not then I have the increment and decrements of my XY stack instructions wrong.

Since I have a dedicated stack pointer (SP), should the XY stack grow towards FFFFh ?  This way both stacks can share the same memory space.  If so, using the above logic, store instructions to the XY stack should be pre incremented, and reads or pops from the stack should be post decremented.  If so then my instructions are still wrong.

Is there anything I am missing?

Discussions

2-Zons wrote 12/12/2018 at 19:54 point

I really would like to have the immediate indirect but I can't see fitting them.  I did overlook push an pop of the status register.  I do have an IRQ input as this is one thing that is impossible to do effectively in software without serious overhead.  I also plan on having a DMA input.   Looks like I need to do some more prioritizing.  Excellent feedback as usual @roelh .  

  Are you sure? yes | no

roelh wrote 12/12/2018 at 20:17 point

For providing the indirect only for load/store A, B, AB you would only need 6 opcodes. You already have 5 spare, and in my other comment I suggest several instructions that could be removed. A DMA input would not need any instructions, provided that you build an external DMA controller. 

But the nice thing of microcode is, that it can be easily changed. Biggest problem is that other tools (assembler, compiler) have to change also in that case.

  Are you sure? yes | no

roelh wrote 12/12/2018 at 08:45 point

In the comment on your previous log, you mention immediate indirect addressing mode (so you could use a memory location as a pointer). I would certainly add that mode (even if only for MOV from/to A, B, AB), because now XY is ment to be a data stack pointer in many situations, there is no other way to use pointers or access arrays.

And for the memory-to-memory moves, it would be good to have both 8 bit and 16 bit versions.

There are still instructions that will hardly be used and can be omitted:
  - stack pointer: load/store to/from memory, and immediate load are enough I think
 - SR: load/store to/from memory, and to/from A and/or B seem enough. You might add SR as destination for immediate AND/OR so you can set/clear condition flags (if you foresee that will be useful). If you plan to use interrupts, SR should have push/pop instructions (but you could also save it to fixed memory location).

 - For ADD/SUB, the (XY+) destination is not needed. Because, when adding to an item on the XY stack,
    the operand is popped from XY but the result is pushed again, so (XY) can be used as destination. This implies that XY should be pointing to the top stack item and not to an empty position.

I agree that the stack should grow downwards, So push is (-XY) and pop is (XY+). So this still has to be changed in the instruction set (so add stack item to A is ADD (XY+),A ) . I think both stacks should behave the same, you will have enough memory for separate stacks so you dont have to 'save' by having them grow towards each other.

In the spreadsheet, several 16 bit instructions are not green yet. It seems that you checked if the source was 16 bit, but you didn't check the destination.

  Are you sure? yes | no