Question: Read and translate assembly programs In this section you'll read two assembly programs. For each one, 1) explain what it does in a sentence or


Read and translate assembly programs In this section you'll read two assembly programs. For each one, 1) explain what it does in a sentence or two, and 2) translate it to pseudocode that uses structured-programming features like if/then, while loops, etc. You can translate to real Python code instead of pseudocode if you prefer. Example (from class): lon ; assume Ri is set to an input value at start LOAD -1, R2 LOAD 5, R3 LOAD 0, R4 loop: ADD R1, R4 ; R4 += R1 ADD R2, R3; R3-- JGZ R3, loop PRINT R4 What it does: Prints RI multiplied by 5. Translation to to structured code: total = 0 times = 5 while times > 0: total += R1 times -= 1 print(total) Problem 1: LOAD 1, R1 LOAD 2, R2 LOAD 100, R3 loop: PRINT R1 ADD R2,R1 MOV R1,R4 NEG R4 ADD R3, R4 JGZ R4, loop Problem 2: ; assume Rl is set to an input value at start JZ R1, end JLZ Ri, label NEG RI label: LOAD 10,R2 ADD R1,R2 JLZ R2, othercase PRINT 1 JMP end othercase: PRINT O end: Write assembly programs Write assembly programs to carry out the following operations. Problem 3: Print the Fibonacci series: 112 35 8 13 21 ... Problem 4: Assume Rl is set to an input value at the start. Print Rl only if it's an even number. (Note: RI might be positive or negative!) Problem 5: Assume Rl and R2 are both set to positive input values at the start. Print the result of dividing RI by R2 in quotient/remainder form. For example, if R1=9 and R2=2, you should print 41; if Ri=9 and R2=3, you should print 30. Read and translate assembly programs In this section you'll read two assembly programs. For each one, 1) explain what it does in a sentence or two, and 2) translate it to pseudocode that uses structured-programming features like if/then, while loops, etc. You can translate to real Python code instead of pseudocode if you prefer. Example (from class): lon ; assume Ri is set to an input value at start LOAD -1, R2 LOAD 5, R3 LOAD 0, R4 loop: ADD R1, R4 ; R4 += R1 ADD R2, R3; R3-- JGZ R3, loop PRINT R4 What it does: Prints RI multiplied by 5. Translation to to structured code: total = 0 times = 5 while times > 0: total += R1 times -= 1 print(total) Problem 1: LOAD 1, R1 LOAD 2, R2 LOAD 100, R3 loop: PRINT R1 ADD R2,R1 MOV R1,R4 NEG R4 ADD R3, R4 JGZ R4, loop Problem 2: ; assume Rl is set to an input value at start JZ R1, end JLZ Ri, label NEG RI label: LOAD 10,R2 ADD R1,R2 JLZ R2, othercase PRINT 1 JMP end othercase: PRINT O end: Write assembly programs Write assembly programs to carry out the following operations. Problem 3: Print the Fibonacci series: 112 35 8 13 21 ... Problem 4: Assume Rl is set to an input value at the start. Print Rl only if it's an even number. (Note: RI might be positive or negative!) Problem 5: Assume Rl and R2 are both set to positive input values at the start. Print the result of dividing RI by R2 in quotient/remainder form. For example, if R1=9 and R2=2, you should print 41; if Ri=9 and R2=3, you should print 30
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
