Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I get this MARIE program to work for negatives? I have to write a progra

ID: 644536 • Letter: H

Question

How can I get this MARIE program to work for negatives? I have to write a program the computes (AB + CD) and I a having trouble when you multiply a negative with a negative (-9*-3) or a negative and zero (0*-9). The program just goes into an infiniti loop. Can you please take a look at my code and let me know if you can see the problem?

HERE IS THE CODE:

org 100
input //Take in the value of the first factor
store x //Stores value of the first factor
input //Take in the value of the second factor
store y //Store value of the second factor
JnS prod //Calls the subroutine
Load sum //load the value of the product from the first two numbers
store ab //stores the value for the product of A and B
input //Again we take in input for the first factor
store x //Store new value
input //Again we take in input for the second factor
store y //Store new value
jns prod //Call the subroutine again
load sum //Load the new product
store cd //Store the product of C and D
load ab //Load the product of A and B
add cd //Add the prodcut of C and D
output //Output the value
halt //End program

sum, dec 0
one, dec 1
ctr, dec 0
x, dec 0
y, dec 0
ab, dec 0
cd, dec 0

prod, hex 0 //product routine is initially 0
load y //load the value of the second factor
store ctr //store it as the control value
clear //resets the AC to 0
store sum //store the value for the added up sum
Loop, Load sum //load the value of the sum
Add x //add the value of the first factor to it
Store sum //store it as the new value of sum
Load ctr //load the value of control value
Subt one //subtract one from it
Store ctr //store that as the new value of the control value
Skipcond 400 //check if the number is equal to 0
Jump Loop //repeats the loop
load sum //loads the value of the sum
JumpI prod //jumps back to the start of the product subroutine

Explanation / Answer

MARIE program for negative numbers:

org 100
Input a /first factor
Store a /store first factor
Input b /second factor
Store b /store second factor
Load a /load first factor
Skipcond 800 /checks if number is zero
Jump End /skips to the end if zero
load b /load second factor
Skipcond 800 /checks if number is zero
Jump End /skips to the end if zero
Loop, Load b /reloads second factor
Subt One /subtracts one from the second factor
Store b /store the new value of the second factor
Load productAB /load the product of the two number; initially zero
Add a /add first factor to the product
Store productAB /store new value to product
Load b/ load second factor again
Skipcond 400 /end loop if b is equal to 0
Jump Loop /repeats the loop
Load productAB /load the value of productAB; no longer 0
End, output /print out results
Halt /end of program

a, Dec 0
b, Dec 0
productAB, Dec 0 /product of the first two numbers
One, Dec 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote