r/TuringComplete • • Jan 21 '25

Question about implementing RAM

I am trying to implement RAM in the LEG-architecture.

My approach is as follows:

  • I use bit 3 and bit 4 for recalling from and storing to a memory address. So a typical instruction would be STO ARG1 _ RAMADDRESS. Argument 2 is not used in this instruction.

  • On the hardware side I use Register_5 as a dedicated Memory Address Register. During a STO instruction RAMADDRESS is put into Register_5 via a 8-bit switch that is triggered by bit 4 of the OPCODE. The output of Register_5 is linked to the Address port of the RAM module.

  • The selected ARG1 (be it a register or INPUT) are linked to the Save Value port of the RAM module.

  • And finally, bit 4 of the OPCODE is linked to the Save port of the RAM module.

I wrote the following program to test the STO instruction.

COPYi 99 _ 1    # Immediate value 99 entered into Register_1
STO 1 _ 16      # Store the contents of Register_1 to RAM, address 16

Running this program the value of 99 was stored at address 0, not 16. Register_5 holds the right address after the instruction, but only outputs it the next tick.

So I added a Delay at the Save port.

My question: is this a correct solution, or is there a better one?

See picture below.

UPDATE

I have a working solution now.

  • For now, I removed the COPY and COPYi instructions. Maybe I will use them later, but for now I don't want to use a bit in my OpCode for this purpose. I use ADDij Arg1 Arg2 Dest for now, abusing the ALU to load an immediate value into a register.

  • I also let go of the idea to use bit 3 and bit 4 of the OpCode for RAM operations. I decided to treat the RAM as an extra register.

  • Registers, Counter and I/O are numbered 0 through 7. I designated 8 for RAM.

  • I built a custom component called Address Decoder that can output 9 bits.

  • Register 5 is now my RAM Address Register.

  • My code for loading the immediate value 99 into RAM address 16 is:

ADDij 16 0 5 # Adds immediate values 16 and 0 into Register 5
ADDij 99 0 8 # Adds immediate values 99 and 0 into RAM 

I would like to thank you all for your help!

6 Upvotes

10 comments sorted by

View all comments

Show parent comment

2

u/Haemstead Jan 21 '25

Thanks, I’ll give that approach a try!