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
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
Related questions
Question
100%
Using lc3 simulator.
use this lc3 simulator:
Write a
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:
-
.ORIG x3000
-
-
; **********************************
-
; REGISTER FUNCTIONALITY
-
; R0: multiplication (X) counter
-
; R1: exponentiation (Y) counter
-
; R2: scratch / math register
-
; R3: result
-
; R4 - R7: unused
-
; **********************************
-
; EXPLANATION
-
; 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.
-
-
; Increment R3 by #1
-
; Load the value of Y (the exponent) into R1 (Y counter)
-
; If zero, branch to the label done (we have a zero power)
-
-
exp ; And R2 with zero (this clears the register)
-
; Load the value of X (the base) into R0 (X counter)
-
; Branch if nonzero to mul (we have a nonzero base, and want to skip the zero case)
-
; And R3 and zero (this handles the zero case)
-
; Branch if zero to done (skip the nonzero steps)
-
-
mul ; 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
-
-
X .FILL x3 ; can be any non-negative 16 bit value
-
Y .FILL x5 ; can be any non-negative 16 bit value
-
.END
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr