I am currently working in the MARIE simulator, and I'm trying to edit the assembly code so that, although it still loops through the six given numbers for addition purposes (15, 25, 20, 30, 35, 10), it checks which of them are smaller than 22, and adds those together while ignoring all numbers > 22. It then needs to display the result in the "output" window of the MARIE simulator
Here is the code I started with:
Load Addr /Load address of first number to be added
Store Next /Store this address is our Next pointer
Load Num /Load the number of items to be added
Subt One /Decrement
Store Ctr /Store this value in Ctr to control looping
Loop, Load Sum /Load the Sum into AC
AddI Next /Add the value pointed to by location Next
Store Sum /Store this sum
Output
Load Next /Load Next
Add One /Increment by one to point to next address
Store Next /Store in our pointer Next
Load Ctr /Load the loop control variable
Subt One /Subtract one from the loop control variable
Store Ctr /Store this new value in loop control variable
Skipcond 000 /If control variable < 0, skip next instruction
Jump Loop /Otherwise, go to Loop
Halt /Terminate program
Addr, Hex 118 /Numbers to be summed start at location 118
Next, Hex 0 /A pointer to the next number to add
Num, Dec 6 /The number of values to add
Sum, Dec 0 /The sum
Ctr, Hex 0 /The loop control variable
One, Dec 1 /Used to increment and decrement by 1
Dec 15 /The values to be added together
Dec 25
Dec 20
Dec 30
Dec 35
Dec 10
This is the code I've modified somewhat; however, all it does is return a list of "5"s instead of the addition of the numbers I need:
Load Addr /Load address of first number to be added
Store Next /Store this address is our Next pointer
Load Num /Load the number of items to be added
Subt One /Decrement
Store Ctr /Store this value in Ctr to control looping
Loop, Load Sum /Load the Sum into AC
Subt 124 /subtracts the value at 124 (22)
Skipcond 800 /if > 22, skip the next instruction
AddI Next /Add the value pointed to by location Next
Store Sum /Store this sum
Output
Load Next /Load Next
Add One /Increment by one to point to next address
Store Next /Store in our pointer Next
Load Ctr /Load the loop control variable
Subt One /Subtract one from the loop control variable
Store Ctr /Store this new value in loop control variable
Skipcond 000 /If control variable < 0, skip next instruction
Jump Loop /Otherwise, go to Loop
Halt /Terminate program
Addr, Hex 118 /Numbers to be summed start at location 118
Next, Hex 0 /A pointer to the next number to add
Num, Dec 6 /The number of values to add
Sum, Dec 0 /The sum
Ctr, Hex 0 /The loop control variable
One, Dec 1 /Used to increment and decrement by 1
Dec 15 /The values to be added together
Dec 25
Dec 20
Dec 30
Dec 35
Dec 10
Dec 22
I'm not sure what I'm doing wrong with the Skipcond to make it put out