我目前正在MARIE模拟器中工作,我正在尝试编辑汇编代码,以便尽管它仍循环遍历六个给定的数字以作加法用途(15、25、20、30、35、10) ,它会检查其中哪个小于22,然后将它们加在一起,而忽略所有大于22的数字。然后,需要在MARIE模拟器的“输出”窗口中显示结果
这是我开始的代码:
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
这是我已经修改的代码;但是,它所做的只是返回“ 5”的列表,而不是添加我需要的数字:
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
我不确定Skipcond出了什么问题