l ; Add R3 and R2 and store in R2 (this will perform the addition step for multiplication) ; Increment R0 by #-1 and store in R0 ; Branch only if positive back to mul (repeat addition)   ; Copy the value in R2 to R3 (what command can we use to do that?) ; Increment R1 by #-1 and store in R1 ; Branch if positive back to exp (repeat multiplication)   done ; halt execution

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter3: Assignment, Formatting, And Interactive Input
Section3.4: Program Input Using Cin
Problem 9E
icon
Related questions
Question
100%

Using lc3 simulator.

use this lc3 simulator: 

Write a program that calculates the result of z = xy
a. Store x and y in memory locations when writing your program (use .FILL)
b. The output of your result, z, should be left in register R3 at the end of your program
c. Assume (6 >= x >= 0) and (6 >= y >= 0)

Psuedo code:

  1. .ORIG x3000
  2.  
  3. ; **********************************
  4. ; REGISTER FUNCTIONALITY
  5. ; R0: multiplication (X) counter
  6. ; R1: exponentiation (Y) counter
  7. ; R2: scratch / math register
  8. ; R3: result
  9. ; R4 - R7: unused
  10. ; **********************************
  11. ; EXPLANATION
  12. ; To perform exponentiation, we can use repeat addition. Exponents are simply a form of repeated multiplication, which is repeated addition. We start with Z = X^0, which is 1. Then, add Z to itself X times to get X^1. Next, add Z to itself X times again which yields X^2. Repeat Y times until we get X^Y.
  13.  
  14. ; Increment R3 by #1
  15. ; Load the value of Y (the exponent) into R1 (Y counter)
  16. ; If zero, branch to the label done (we have a zero power)
  17.  
  18. exp ; And R2 with zero (this clears the register)
  19. ; Load the value of X (the base) into R0 (X counter)
  20. ; Branch if nonzero to mul (we have a nonzero base, and want to skip the zero case)
  21. ; And R3 and zero (this handles the zero case)
  22. ; Branch if zero to done (skip the nonzero steps)
  23.  
  24. mul ; Add R3 and R2 and store in R2 (this will perform the addition step for multiplication)
  25. ; Increment R0 by #-1 and store in R0
  26. ; Branch only if positive back to mul (repeat addition)
  27.  
  28. ; Copy the value in R2 to R3 (what command can we use to do that?)
  29. ; Increment R1 by #-1 and store in R1
  30. ; Branch if positive back to exp (repeat multiplication)
  31.  
  32. done ; halt execution
  33.  
  34. X .FILL x3 ; can be any non-negative 16 bit value
  35. Y .FILL x5 ; can be any non-negative 16 bit value
  36. .END
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Avoiding deadlock
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr