2014-11-04 113 views
0

所以,我在使用MARIE模拟器时遇到了一个问题。这里是提示:我不知道为什么这个MARIE SIM代码不能正常工作

define a decimal variable X and set X = 0  
define a decimal variable Y and set Y = 0 

Input a number in decimal form from the keyboard 
store the number in location X 
Input a number in decimal form from the keyboard 
store the number in location Y 

If X > 0, then 
    X = X + 5 
Else 
    X = Y - 2 
Endif 
Display X using the output instruction 

编辑:当前的代码:

  org 100 
      input 
      store X 
      input 
      store Y 
      load X 
      skipcond 800 
      Jump Else 
      load X 
      Add A 
      store X 
      jump Endif 
Else,  load Y 
      Subt B 
      store X 
Endif, Load X 
      Output 
      Halt 

X,  dec 0 
Y,  dec 0 
A,  dec 5 
B,  dec 2 

我的问题来自于一个事实,当你运行它,数学不出来正确。例如,如果你输入4代表X,那么答案应该是7,当它是9时。任何人都可以指出我出错的地方吗?

回答

0

让我知道这对你的作品:

org 100 
    input 
    store X 
    input 
    store Y 
load X 
    skipcond 800 

Jump Else 
    load X 
    Add Addr 
    store X 
    jump Endif 
Else, load Y 
    Subt Subtr 
    store X 
Endif,  Load X 
    Output 
    Halt 
X,  dec 0 
Y,  dec 0 
Addr, dec 5 
Subtr, dec 2 
+0

不幸的是,它遭受着与我目前相同的问题。 if的X部分很好,但是如果去到else,输出总是2,不管Y的输入是什么。 – Monobus 2014-11-05 03:39:34

+0

你在输入什么内容和输入的结果?当我输入4为x和10为它在我的女友模拟输出9。当我为x输入-5,然后输入7为Y mt时,十进制输出为5.您是否正确保存并确保更新了以前的代码,或者尝试创建一个新的空白编辑并粘贴我发布并保存和组装的内容那么,然后测试我提供的输入,看它是否相同。 – Chef 2014-11-05 17:38:38

+0

尽快尝试直接copyong,只要我到我的电脑。 – Monobus 2014-11-05 21:09:42

0

你的错误是如何以及何时使用skipcond。由于您在阅读Y后立即使用它,所以用户输入的内容仍然在AC中,例如,如果输入4和10,则最终将输入15(10 + 5),然后直接跳到endif。

你想要做的是将X加载回AC,然后skipcond检查它,并进入其余的逻辑。您可能还想使用更多jump以确保您正在执行正确的块。

+0

的X部分是现在工作(后正常加载X),而Y是仍然不正确。我仔细检查了正确的装载,但仍然没有雪茄。 – Monobus 2014-11-04 20:26:33

+0

你能用我们现在的代码更新我们吗? – wmassingham 2014-11-05 15:05:18

+0

现在更新。 – Monobus 2014-11-05 15:24:13