2010-10-25 71 views
0

我學習裝配使用MARIE程序,但我無法弄清楚熱從書做這樣一個問題:MARIE除以一個數除以另一個數

除以一個數除以另一個數和存儲商和其餘的在兩個不同的存儲位置。

這就是我到目前爲止,我做錯了什麼?僅供參考,程序中沒有分割或乘法,因此我必須使用循環來完成,但我想我錯過了一些東西。

如果你想用反覆的減分的程序都可以在這裏http://computerscience.jbpub.com/ecoa/2e/downloads/MarieSim-v1.3.01.zip

ORG 100 
Input   /Enter a number 
Store X  /Saves the number 
Input   /Enter a number 
Store Y  /Saves the number 
Load Zero  /Move 0 into AC 
Store Z  /Set Z to 0 
If, Load Z /Load Z 
Skipcond 400 /If AC=0 (Z=0), skip the next instruction 
Jump Endif /Jump to Endif if X is not greater than 1 
Then, Load X 
Subt Y  /X - Y 
Store X  /X = X - Y 
Endif, Load Z /Load Z into AC 
Add One  /Add 1 to Z 
Store Z  /Z = Z + 1 
Output  /Print to screen 
Halt   /Terminate program 
X, Dec 0  /X has starting value 
Y, Dec 0  /Y has starting value 
Z, Dec 0 
One, Dec 1 /Use as a constant 
Zero, Dec 0 /Use as a constant 
END 
+1

評論太多。 :P – cHao 2010-10-25 01:20:29

+2

而你仍然點擊「添加評論」? :) – 2010-10-25 16:46:25

回答

0

了,你的程序最好有某種形式的一個循環。

你的程序結構的方式,它會直接運行到Halt指令後從X中減去Y只有一次,而Z最終會成爲一個。

最好是手動完成代碼並在一張紙上執行每一步,然後你會看到你出錯的地方。順便說一下,關於Jump Endif的評論是錯誤的,它不是X,而是你正在檢查的Z.

你可能想要修改你的代碼,然後你的問題是否仍然存在問題。

-1
////Divide Positive numbers/ A have to be biger then B///by: E 

    ORG 100 
    Input /Input A value 
    Store A 
    Input /Input B value 
    Store B 

    If, Load A 
    Skipcond 800 
    Jump EndIf 
    Then, Load A 
    Subt B 
    Store A 
    Load C 
    Add One 
    Store C 
    Jump If 
    EndIf, Load C 

    Halt, Output 


    C, DEC 0 
    A, DEC 0 
    B, DEC 0 
    One, DEC 1 
相關問題