Using the MARIE computer assembly language, write a program that computes the fo
ID: 3830915 • Letter: U
Question
Using the MARIE computer assembly language, write a program that computes the following expression:z <-- (a * b) * (c * d). The computer will read in the input values a, b, c, and d from the keyboard, and thefinal result (z) has to be displayed. In addition, every time an input value is read in, it must be displayed on the screen. Each instance of multiplication should be carried out via your own multiplication subroutine. Remember that the instruction set does not have an instruction to execute multiplication, you must write one. The program must be tested in the MARIE simulator.
Explanation / Answer
First let me give you the program:
ORG 100
Load A
Store W
Load B
Store X
JnS Mul
Load Sum
Store Re1
Load C
Store W
Load D
Store X
JnS Mul
Load Sum
Store Re2
Load Re1
JnS Mul
Load Sum
Store FRe
Halt
A, Dec ?
B, Dec ?
C, Dec ?
D, Dec ?
W, Dec 0
X, Dec 0
Ctr, Dec 0
One, Dec 1
Re1, Dec 0
Re2, Dec 0
FRe, Dec 0
Sum, Dec 0
Mul, Dec 0
Load X
Store Ctr
Clear
Store Sum
Loop, Load Sum
Add W
Store Sum
Now let me give you the Explaination:
First I loaded the parameter A and then store it in the variable named 'W'
Load A
Store W
Then
I loaded the parameter B and then store it in the variable named 'X'
Load B
Store X
Then I jumped to multiplication subroutine
Then I got the result
Then I stored it in temporary storage variable 'Re1'
Then I jumped to multiplication subroutine
Then I got the result
Then I stored it in temporary storage variable 'Re2'
Now I loaded the first result
Then I jumped to multiplication subroutine
Then I got the result
Then I stored it in temporary storage variable 'FRe'
Then Halt, which is termination of the program
Halt
Then I asked for parameters A,B,C,D
A, Dec ?
B, Dec ?
C, Dec ?
D, Dec ?
Then parameters W and X are declared
W, Dec 0
X, Dec 0
Counter for looping Ctr and a constant variable with value 1 is created
Ctr, Dec 0
One, Dec 1
Temporary storage variables 'Re1', 'Re2', 'FRe' are declared
Re1, Dec 0
Re2, Dec 0
FRe, Dec 0
Declared Sum
Sum, Dec 0
the below line stores return address
Mul, Dec 0
To load the second parameter to use as counter I did the following
Load X
To store counter
Store Ctr
To clear sum
Clear
To rewrite the value in Sum to 0 to start again I did as below
Store Sum
To load Sum
Loop, Load Sum
To add First parameter
Add W
To store result in Sum
Store Sum
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.