I am trying to get my program to do a simple math problem of A*B+C*D given a set of test numbers. I have the code written out, but after I input numbers for A and B it goes into an infinite loop. My code is this:

``````ORG  100
Store  X /Store A in first parameter
Store Y /Store B in second parameter
Store  E /E:= A x B
Store X /Store C in first parameter
Store Y /Store D in second parameter
Store F /F := C x D
Add F /AC now contains sum of A X B + C X D
Halt /Terminate program
A, Dec 0 /Initial values of A,B,C,D not given in problem
B, Dec 0 / (give values before assembling and running)
C, Dec 0 /
D, Dec 0 /
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
Store Ctr /Store as counter
Clear /Clear sum
Store Sum /Zero out the sum to begin
Store  Sum /Store result in Sum
Subt One /Decrement counter
Store Ctr /Store counter
SkipCond  400 /If counter = 0 finish subroutine
Jump Loop /Continue subroutine loop
END``````

And the set of test number I am using is this:
Number set 1: A=2 B=3 C=4 D=5 with an output of 26
set 2: A=1 B=1 C=1 D=1 with an output of 2
set 3: A=8 B=3 C=3 D=2 with an output of 30

Thank you!

Ok so i have gotten the code to work, but my new problem is that whenever I try to input a new number into the simulator it give me the output for the last set of numbers. Here is my new code.

``````ORG  100
Input
Store  X /Store A in first parameter
Input
Store Y /Store B in second parameter
Store  E /E:= A x B
Input
Store X /Store C in first parameter
Input
Store Y /Store D in second parameter
Store F /F := C x D

Add E  /AC now contains sum of A X B + C X D
Store G /Store F into temp storage
EndLoop, Load G /Get full result
Output
Halt /Terminate program
A, Dec -5 /Initial values of A,B,C,D not given in problem
B, Dec 4 / (give values before assembling and running)
C, Dec 4 /
D, Dec 1 /
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
G, Dec 0 /Temp storage
Sum, Dec 0
Mul, Hex 0 /Store return address here
Store Ctr /Store as counter
Clear /Clear sum
Store Sum /Zero out the sum to begin
Store  Sum /Store result in Sum
Subt One /Decrement counter
Store Ctr /Store counter
SkipCond  400 /If counter = 0 finish subroutine
Jump Loop /Continue subroutine loop
END``````

Line 27-30 are causing this problem, but I do not want to change the code to make the number set match. Any ideas? Thanks

if M <= N then
N = N + 6;
else if M != O
then N = N – 6;
else O = O + 6;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.