0

我目前在 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 时做错了什么

在此处输入图像描述

4

0 回答 0