2014-11-04 114 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