Close

Branching

A project log for One-instruction TTL Computer

A breadboard-able computer which uses only a single instruction - MOVE

justin-davisJustin Davis 04/24/2017 at 12:541 Comment

I've spent some time figuring out how to branch. The first problem is my program counter is 16-bits. So I figure I will have a temporary register hold the upper byte. This is written first. Then when the lower byte is written to, it will also copy over the temporary byte to load the PC all at once. So if you are jumping within the same page, you can copy the current upper byte over to this place, or if it's already there from a previous jump, then do nothing. So all jumps are absolute.

Next I think what I may try is to create a pointer register. So when I write to the pointer register, it contains a memory location. Then when I write to the a different address, instead of writing that data to that address, it writes to whatever address the pointer register is pointing to. So if my pointer register contains $00, then it will do a write to the $00 register next. Or if it's value is $01, the next data write goes to the $01 register. It overrides the destination register. This may be tricky to implement, but I'll worry about that later. If I make $00 a trash register and $01 the program counter, then that sets me up for my branching.

The next problem is how to "decide" when to branch and when not to. So most branches are "branch if equal to" or "branch if less than" type of decisions. They are tied to an ALU execution. I have the carry out bit and an operand equality bit. Both of these can be used to decide to branch or not. I can write the equality bit to it's own register. Then I can copy the contents of this register to the pointer register, and then write my branch address. In other words, to do a "branch if equal" command:

  1. Copy first value to ALU A register
  2. Copy second value to ALU compare address (this sets the equality bit in the equality register)
  3. Copy equality register to pointer register
  4. Copy branch address to pointer's target register (writes the branch address to either $00 or $01)
    1. So either the address was written to the trash register in which case nothing happens and the program counter falls through to its next location OR
    2. The program counter gets written to with a new address which executes the branch

The pointer register could be useful for many other things as well other than branching. You could have it target a place in memory dependent on an ALU result. For example, you want to write to a memory array. Add the array root memory location to an index to offset the memory location. And then write your data to that spot.

Anyway, I need to figure out how to do the implementation of the pointer register which might be tricky. I'll think about it while I finish up a few other things.

Discussions

Yann Guidon / YGDES wrote 04/24/2017 at 13:02 point

Pointer registers are another way of speaking about "register-mapped memory", which I use for the #YGREC16 - YG's 16bits Relay Electric Computer and the #YASEP Yet Another Small Embedded Processor :-)

They can be traced back to the CDC6600 with its A registers, 5 of them are mapped to the read port of memory, and 2 trigger a write when the address is written to.

Whether you decide to use the single-port (my way) approach or if you separate read and write registers, is up to you. If you have a wide register addressing range, the CDC6600 way might be better, but you have to try and see...

  Are you sure? yes | no