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
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 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
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
SkipCond  400 /If counter = 0 finish subroutine
Jump Loop /Continue subroutine loop
JumpI Mul /Done with subroutine, return to main
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 
Load A
Store  X /Store A in first parameter
Input
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
Input
Load C
Store X /Store C in first parameter
Input
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 F
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
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
SkipCond  400 /If counter = 0 finish subroutine
Jump Loop /Continue subroutine loop
JumpI Mul /Done with subroutine, return to main
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

This question has already been answered. Start a new discussion instead.