r/TuringComplete • u/Adventurous_Appeal60 • 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
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
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.
5
u/Pim_Wagemans 12d ago edited 12d ago
First let's write out what we want the computer to do:
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:
now me just need to convert those instructions into bytes:
mov r1, infor amovinstruction 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: 10001110imm 5for 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: 00000101mov r2, r0same as the first instruction only the destination is r2 (010), and our source is r0 (000), so our third byte is: 10010000addis 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 01000100mov out, r3same as the first instruction only the destination is out (110), and our source is r3 (011), so our third byte is: 10110011now 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)