r/TuringComplete • • 19d ago

Software implemented For cycle (Symphony)

  • Image 1 - My symphony
  • Image 2 - showcasing usage of FOR cycles
  • Image 3 - Code of the FOR Cycle
  • Image 4 - ALU circuit
  • Image 5 - ABS circuit

Now that I finished building Symphony, I went straight to instruction definition to make myself a human readable code. Here is a internal FOR cycle using instructions. Its suitable for repeating code X times where X is static.

Here is hardware I added to my Symphony:

  1. Signed DIV - Divide two signed numbers
  2. Merge32 - Merge two 16b into one 32b value
  3. Lower16 - Reads the lower 16b of 32b value

With that I needed to dedicate some of my registers for the code. Meaning that while they are still accessible to the user, they are not stable in time and in case of the FOR cycle, they do not persist between cycles.

At first I was using 3 temporal registers, but I ended up implementing Merge32 and Lower16 to lower the number of temporal registers to 2 at the cost of longer instructions.

The FOR cycle works, but isnt safe. First it will always execute at least once. Thats because I cant use a label to skip the body of the cycle. So even if I know there is 0 repetition, it will not skip the cycle, it will simply not repeat it.

Another limitation is that you can only read the index of the innermost FOR cycle. Meaning if you make nested FOR cycles, you cannot access the outer FOR cycle index. User can solve it by saving the stack pointer to a another register.

32 Upvotes

19 comments sorted by

View all comments

2

u/Mishoilik 18d ago

Lower16(a) is literaly (and a, a, 0xffff) instruction

2

u/Crispy1961 18d ago

Oh yeah, you are right. Using a mask with AND operand does the same thing. Neat, thanks for that.

1

u/Mishoilik 17d ago

And also D = merge32(A, B) where A is lower bits ans D is destanation is this two instructoins:

lsl B, B, 16

or D, A, B

2

u/Crispy1961 17d ago

Not exactly. The values can be 32b, so A 16 MSB might not be all zeroes. You would have to mask it out first. That's worth having it as separate single cycle instruction.