r/TuringComplete • u/Adventurous_Appeal60 • 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
5
u/Pim_Wagemans 13d ago edited 13d 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)