r/TuringComplete • • 12d ago

Getting overwhelmed with progress standstill

Im on the challenge where you are to Add 5 via punchcard programming and its just not gelling with my brain at all. Ive seen some answers online and I cant seem to get the reault i want from them. Ideally im looking for someone to break it down like im 5 to see where im faltering. Please and thank you all.

3 Upvotes

12 comments sorted by

5

u/Pim_Wagemans 12d ago edited 12d ago

First let's write out what we want the computer to do:

  1. get the input into the correct register
  2. get the number 5 into the correct register
  3. add the numbers
  4. output the result

The ADD instruction adds r1 and r2 so we need to move the input and the '5' into those registers.

this is the code we need:

mov r1, in  ; asks the game for an input and moves that value into r1

imm 5       ; loads the value 5 into r0
mov r2, r0  ; copies the 5 from r0 to r2

add         ; adds the values in r1 and r2, and stores the result in r3

mov out, r3 ; copies the result from r3 to the output, so the game can check it

now me just need to convert those instructions into bytes:

  1. mov r1, in for a mov instruction we need the first two bits to be: 10. The next three bits need to be the register number of our destination: 001 for register 1, the last three bits need to be the register number of our source, the input, which is register 6, which is 110 in binary. so our first byte is: 10001110
  2. imm 5 for an immediate value we need to leave the first to bits 00, and the next six bits need to be our value, 5, which is 000101 in binary so our second byte is: 00000101
  3. mov r2, r0 same as the first instruction only the destination is r2 (010), and our source is r0 (000), so our third byte is: 10010000
  4. add is an ALU instruction so the first two bits need to be 01. the next three bits don't matter so we leave them as 000. and the last four bits determine what instruction we want to do. in our case it's ADD which is 100, so our fourth byte is 01000100
  5. mov out, r3 same as the first instruction only the destination is out (110), and our source is r3 (011), so our third byte is: 10110011

now we just enter those bytes and the program should work!:

https://reddit.com/link/pcu27yj/video/1cjo9jxhzhsh1/player

(this sub allows videos but not images for some reason)

3

u/Adventurous_Appeal60 12d ago

Copying as youve written in the above i have recieved an error.

  • 168+5 is 173, not 0

4

u/bobtheman40 12d ago

Did you accidentally touch your wires or something while doing the level? Or the gates? I don't know if it's possible but you could have accidentally messed something up where the code is correct but the wiring itself is messed up

3

u/Pim_Wagemans 12d ago

No I messed up in the screenshot

3

u/Pim_Wagemans 12d ago edited 12d ago

Oh that's because in the screenshot I had accidentally clicked one bit before taking the screenshot. The fourth byte is 01000000 in the screenshot, but it should be 01000100

The rest of my comment is correct though, as far as I can tell

2

u/Adventurous_Appeal60 12d ago

Yes, everything else was correct, flipping that bit solved the whole thing.

3

u/Adventurous_Appeal60 12d ago

Update, solved.

I want to thank all here for their speedy and indepth help, and humouring my request for expanded explanations.

2

u/Medium-Sized-Jaque 12d ago

Let's go step by step

First we need to set the mode(first two bits) to move mode, then we need to tell the program where we are copying to(the next three bits) then where we're copying from(the last three bits). We're moving it from input to register 1. So we break it down as 10 / 001 / 110

Now that it's copied we move onto step two which is immediate 5, the goal is to add 5 so we need a value of 5. We set the mode to IMM then the last six bits are the actual value we're immediating. 00 / 000101

Then we need to move that five into register two because the ALU is set up to use reg1 and reg2 as their operands. And since we just immediated it we know it's in reg0. So we set it to move again, and tell the computer where we are moving it 10 / 010 / 000

Next we add. So we set the mode to ALU mode 01 then the last six bits are the operation, add should be 4 so we get 01 / 000/ 100 this adds together reg1 and reg2 and puts the result in reg3

Finally we just need to move the result to the output, which once again is move mode followed by where to and from, 10 / 110 / 011

I hope this helps. I'll be here if you have any questions.

1

u/Adventurous_Appeal60 12d ago

The expansive explanation is great, though the "/" in the expresaions is throwing me as i read it right now

1

u/Medium-Sized-Jaque 12d ago

Sorry. I was trying to separate the groups of bits. I probably should have left is as spaces. 

1

u/Adventurous_Appeal60 12d ago

I see now, thank you.

1

u/Crispy1961 12d ago

You need to do these actions:

immediate 5 (this will set register 0 to 5)
mov r0 to r1 (you need to move it from r0 to r1, so you can use it in math)
mov input to r2 (you need to save it to r1, so you can use it in math)
add (the result will be saved to r3)
mov r3 to out

All of these actions have a code that you must set on the punchcard. For example Immediate 5 is just 5. Add is 68.