Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an LC3 program that includes- a main function (code located at the top of

ID: 3724837 • Letter: W

Question

Write an LC3 program that includes- a main function (code located at the top of your program)- a function MULT that

calculates the product of two non-negative numbers
The main function should load two values from variables named FACT1 and FACT2, initialized to 3 and 8. Call MULT using those values, store the result in a variable named PRODUCT.

The function MULT must be a close translation of the code shown below. It must be recursive and make use of the stack for local variables (when saving register values, for example). Use registers to send parameters and return values. The callee must save and restore registers as necessary. There is a simpler recursive version of multiply, but you must implement this one.

Explanation / Answer

#include <stdio.h>
int MULT(int FACT1, int FACT2)
{
int result;
if(FACT1==0)
{FACT2 = FACT2 + FACT2;
return FACT2;}
else
{
MULT(FACT1-1, FACT2);
result = FACT2 + FACT2;
}
  
return result+FACT2;
}
int main()
{
int FACT1 = 3, FACT2 = 8, PRODUCT=0;
PRODUCT = MULT(FACT1, FACT2);
printf("PRODUCT = %d", PRODUCT);

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote