Using the MARIE computer assembly language, write a program that computes the fo
ID: 3817163 • 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
Code:
INPUT //GET INPUT VALUE
STORE X //STORE INPUT VALUE INTO X
OUTPUT M[X] //DISPLAY INPUT VALUE
INPUT
STORE Y
OUTPUT M[Y]
CLEAR
FOR_INIT, LOAD ONE //WE ARE LOADING ONE
STORE
FOR_COND, LOAD I
SUBT Y
SKIPCOND 800
JUMP FOR_BODY
JUMP END_FOR
FOR_BODY,
AC<- X
ADD X
STORE Z
AC<-Z
LOAD I
ADD ONE
STORE I
JUMP FOR_COND
END_FOR
INPUT
STORE A
OUTPUT M[A]
INPUT
STORE B
OUTPUT M[B]
CLEAR
FOR_INIT, LOAD ONE
STORE
FOR_COND, LOAD I
SUBT B
SKIPCOND 800
JUMP FOR_BODY
JUMP END_FOR
FOR_BODY,
AC<- A
ADD A
STORE C
AC<-C
LOAD I
ADD ONE
STORE I
JUMP FOR_COND
END_FOR
CLEAR
FOR_INIT, LOAD ONE
STORE
FOR_COND, LOAD I
SUBT C
SKIPCOND 800
JUMP FOR_BODY
JUMP END_FOR
FOR_BODY,
AC<- Z
ADD Z
STORE K
AC<-K
LOAD I
ADD ONE
STORE I
JUMP FOR_COND
END_FOR
OUTPUT M[K]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.