SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Linda Null ,julia Lobur
Chapter:
Marie An Introduction To A Simple Computer
Exercise:
Exercises
Question:16 | ISBN:9780763704445 | Edition: 3

Question

Write a MARIE program to evaluate the expression AxB + CxD.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

A MARIE program to evaluate the expression AxB + CxD are shown below:

ORG 100
Load  A
Store X      /Store A in first parameter
Load  B
Store Y      /Store B in second parameter
JnS    Mul   /Jump to multiplication subroutine
Load  Sum          /Get result
Store E      /E:= A x B
Load  C
Store X      /Store C in first parameter
Load  D
Store Y      /Store D in second parameter
JnS   Mul   /Jump to multiplication subroutine
Load  Sum          /Get result
Store F      /F := C x D
Load  E      /Get first result
Add   F      /AC now contains sum of A X B + C X D
Halt           /Terminate program
A,      Dec ?         /Initial values of A,B,C,D not given in problem
B,      Dec ?         / (give values before assembling and running)
C,      Dec ?         /
D,     Dec ? /
X,      Dec 0         /First parameter
Y,      Dec 0         /Second parameter
Ctr,   Dec 0         /Counter for looping
One, Dec 1         /Constant with value 1
E,      Dec 0         /Temp storage
F,      Dec 0         /Temp storage
Sum, Dec 0
Mul,   Hex 0         /Store return address here
Load Y               /Load second parameter to be used as counter
Store Ctr            /Store as counter
Clear                           /Clear sum
Store Sum          /Zero out the sum to begin
Loop, Load Sum /Load the sum
Add   X               /Add first parameter
Store Sum          /Store result in Sum

           Load  Ctr
           Subt  One          /Decrement counter
           Store Ctr            /Store counter
           Skip  Cond 400   /If counter = 0 finish subroutine
           Jump Loop          /Continue subroutine loop
           JumpI Mul           /Done with subroutine, return to main
           END

 

0 0

Discussions

Post the discussion to improve the above solution.