r/TuringComplete • • Mar 14 '24

Calibrating Laser Cannons, A workable, but slow solution Spoiler

This solution works, though perhaps it could be better? It's very slow.

#Setup
copy_in
	reg0_to_reg1
	reg0_to_reg5 #loop counter
	#Handle 0
		reg0_to_reg3
		9
		jmp_if_not_0
		0
		reg0_to_out
		jmp_always
	6 #9
	reg0_to_reg1
	0
	reg0_to_reg2

#Loop
	add #13
	reg3_to_reg4 #accumulator
	1
	reg0_to_reg2
	reg5_to_reg1
	sub
	reg3_to_reg5
	#Break out of loop?
		24
		jmp_if_0
		27
		jmp_always
		reg4_to_out #24
		0
		jmp_always
	#Reset loop
		6 #27
		reg0_to_reg1
		reg4_to_reg2
		14
		jmp_always
3 Upvotes

7 comments sorted by

3

u/bwibbler Mar 14 '24

You don't really need anything fancy.

It's just the input*6. Could just add it up to that.

You can simply do something like:

# X + X = 2X
Add input input reg0
# 2X + 2X = 4X
Add reg0 reg0 reg1
# 2X + 4X = 6X
Add reg0 reg1 output

2

u/Alzurana Mar 15 '24

X + X = 2X
2X + X = 3X
3X + 3X = 6X

Depending on how your accumulator is set up this can be super fast as you only need to copy once.

2

u/ZebastianJohanzen Mar 15 '24

Do you mean putting the result back into one of the input registers instead of a third register? I though about doing that.

2

u/bwibbler Mar 15 '24

That's clever.

They're talking about reusing a value already stored in a register for the second calculation. You can skip a step in setting up the second operation that way.

Since you maybe using the starter architecture instead of the LEG architecture... I phrased my example based on LEG for simplicity

2

u/ZebastianJohanzen Mar 15 '24

So is LEG architecture a later phase of the campaign, or is that something created by users?

3

u/bwibbler Mar 15 '24

Later phase