1.1. Multiplication Write a multiplication subroutine that takes two values and
ID: 3861301 • Letter: 1
Question
1.1. Multiplication Write a multiplication subroutine that takes two values and multiplies them together. The two input values should be stored in R1 and R2 before multiplication is called, and the result should be stored in R0 before multiplication returns. Write multiplication to start at x3100. Lecture 7 has a pretty strong start on this subroutine already.
1.2. Division Write a division subroutine that takes two values and divides the first by the second. The numerator should be stored in R1 and the denominator in R2 before division is called, and the result should be stored in R0 before division returns. Since LC-3 only has integers, any remainder should be ignored. Think about how division can be implemented with the tools that we have already – addition and subtraction. Write division to start at x3200.
1.3. Modulo Write a modulo subroutine that takes two values and mods the first by the second. As a reminder, a mod b gives the remainder of a ÷ b. The dividend should be stored in R1 and the divisor in R2 before modulo is called, and the result should be stored in R0 before modulo returns. Write modulo to start at x3300.
1.4. Simple test Write some code to test your three operations. Put 5 in R1 and 3 in R2 before each your tests. That way you can test that R0 is 15 after multiplication, 1 after division, and 2 after mod. You don’t need to print anything out in the test – this is a test that you will step through in debug mode to verify your R0 return values. Write the test to start at x3000 (so all of your operators should be branching/jumping back to the appropriate location in your test code).
1.1. Multiplication Write a multiplication subroutine that takes two values and multiplies them together. The two input values should be stored in R1 and R2 before multiplication is called, and the result should be stored in Ro before multiplication returns. Write multiplication to start at x31oo. Lecture 7 has a pretty strong start on this subroutine already 1.2. Division Write a division subroutine that takes two values and divides the first by the second. The numerator should be stored in R1 and the denominator in R2 before division is called, and the result should be stored in Ro before division returns. Since LC-3 only has integers, any remainder should be ignored. Think about how division can be implemented with the tools that we have already addition and subtraction. Write division to start at x320o 1.3 Modulo Write a modulo subroutine that takes two values and mods the first by the second. As a reminder, a mod b gives the remainder of a b. The dividend should be stored in R1 and the divisor in R2 before modulo is called, and the result should be stored in Ro before modulo returns. Write modulo to start at x33oo. 1.4. Simple test Write some code to test your three operations. Put 5 in R1 and 3 in R2 before each your tests. That way you can test that Ro is 15 after multiplication, 1 after division, and 2 after mod. You don't need to print anything out in the test this is a test that you will step through in debug mode to verify your Ro return values. Write the test to start at x30oo (so all of your operators should be branching/jumping back to the appropriate location in your test code)Explanation / Answer
This is the code in assembly language program to print the multiplication of two numbers which are in registers.
Multiplication:
Start
Mult R1,R2
Lw R3,R1
Sw R3, x[3100]
jr x[3000];
Ends
Division:
Start
Div R1,R2
Mflo R1
Lw R3,R1
Sw R3, x[3200]
jr x[3000];
Ends
ModuloDivision:
Start
Div R1,R2;
Mfhi R1;
Lw R3,R1;
Sw R3, x[3300];
jr x[3000];
Ends
Start
Main:
li R1,5;
li R2,3;
jal Multiplication;
jal Division;
jal ModuloDivision;
ends;
Explanation:
The instruction “lw” means “load word”. It copies data from memory to a specified register.
The instruction “sw” means “store word”. It copies data from a register to memory.
The instruction “mflo” stores only the quotient and leaves the reminder.
The instruction “mfhi” stores only the reminder, hence modulo division operation has been performed.
The instruction "jal" is used to call the procedure.
The instruction "jr" is used to return to the procedure.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.