172k views
2 votes
Using the MARIE computer assembly language, write a program that computes the following expression: z=a∗ b∗c. The computer will read in the input values a,b, and c from the keyboard and the final result (z) have to be displayed. In addition, every time an input value is read in, it must be displayed on the screen. Remember that the instruction set does not have an instruction to execute multiplication.

Note: If any of the input values a,b, and c is a negative numbers or a zero, then the result printed should be "0". Otherwise, the result of the multiplication must be printed.
The program must be tested on MARIE simulator.

User Blami
by
7.9k points

2 Answers

3 votes

Final answer:

In MARIE assembly language, to calculate the product of three numbers (a, b, c), one must use repeated addition due to the lack of direct multiplication support, with checks for zero or negative inputs to output zero in those cases. The program involves reading inputs, checking for validity, displaying them, and performing the necessary calculations.

Step-by-step explanation:

In MARIE assembly language, to compute the expression z = a * b * c, where a, b, and c are input values, we need to implement multiplication through repeated addition and ensure that if any input is zero or negative, we output zero. Here is a program outline that performs this operation: Start the program and prompt the user for input. Read the first number (a), and display it.

Check if a is zero or negative. If it is, skip to the end and output zero. Read the second number (b), and display it. Check if b is zero or negative. If it is, skip to the end and output zero. Read the third number (c), and display it. Check if c is zero or negative. If it is, skip to the end and output zero. Perform repeated addition to emulate multiplication between a and b, storing the intermediate result.

Perform repeated addition to multiply the intermediate result by c, arriving at the final result z. Output the result z. Halt the program. Since MARIE does not support multiplication directly, repeated addition is used where we add a to itself b times and then multiply the result by c using the same method.

User Lonegunman
by
7.7k points
4 votes

Final answer:

A MARIE assembly language program is provided to compute the product of three numbers, with checks for zero or negative inputs. The program uses repeated addition to simulate multiplication and prints the input numbers as well as the product, unless any input is zero or negative, in which case it prints '0'.

Step-by-step explanation:

Writing an assembly language program for the MARIE computer that computes the product of three numbers involves multiple steps since MARIE lacks a built-in multiplication instruction.

In this scenario, you'd need to perform multiplication through repeated addition and implement checks for zero or negative inputs to ensure that the output is accurate according to the given conditions.

To handle input and output operations, we use the INP and OUT instructions respectively. For testing whether a number is zero or negative, comparisons are done by subtracting the inputs from zero.

If any input is negative or zero, the program will display '0' as the result. Multiplication is simulated by adding a number to itself repeatedly. Below is a sample program that would perform the required operations:
InputA INP / Read input a
OUT / Print a
STOR A
SUBT Zero
SKIPCOND 800
JUMP Continue
JUMP PrintZero
InputB INP / Read input b
OUT / Print b
STOR B
SUBT Zero
SKIPCOND 800
JUMP Continue2
JUMP PrintZero
InputC INP / Read input c
OUT / Print c
STOR C
SUBT Zero
SKIPCOND 800
JUMP Multiply
JUMP PrintZero

Continue JUMP B
Continue2 JUMP C

Multiply LOAD A
STOR Z
LOAD B
SUBT One
SKIPCOND 800
JUMP Done
LOAD Z
ADD A
STOR Z
LOAD B
SUBT One
STOR B
JUMP Multiply

Done LOAD Z
OUT / Print z
JUMP End

PrintZero LOAD Zero
OUT / Print 0

End HALT

A, DEC 0
B, DEC 0
C, DEC 0
Z, DEC 0
Zero, DEC 0
One, DEC 1

This program will read in values for a, b, and c, display them, and then proceed to calculate the product only if all the numbers are positive. Otherwise, it will print '0'. It assumes that the memory locations for A, B, C, and Z have been declared, and uses the labels Zero and One to help in the computations and checks.

User Bert Neef
by
7.2k points