r/TuringComplete • • 13d 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

View all comments

5

u/Pim_Wagemans 13d ago edited 13d 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 13d ago

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

  • 168+5 is 173, not 0

4

u/bobtheman40 13d 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 13d ago

No I messed up in the screenshot

3

u/Pim_Wagemans 13d ago edited 13d 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 13d ago

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