【问题标题】:M.A.R.I.E divide one number by anotherM.A.R.I.E 将一个数字除以另一个数字
【发布时间】:2010-10-25 00:58:22
【问题描述】:

我正在使用 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

【问题讨论】:

  • 你还是点击了“添加评论”? :)

标签: assembly marie


【解决方案1】:

如果你想使用重复减法进行除法,你的程序最好有某种形式的循环。

您的程序的结构方式是,在从 X 中减去 Y 一次后,它将直接运行到 Halt 指令,并且 Z 最终将是一。

最好手动检查代码并在一张纸上执行每个步骤,然后您就会看到哪里出错了。顺便说一句,Jump Endif 上的评论是错误的,你检查的不是 X,而是 Z。

您可能想修改您的代码,然后再修改您的问题是否仍然存在问题。

【讨论】:

    【解决方案2】:
    ////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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      • 2016-10-02
      • 1970-01-01
      相关资源
      最近更新 更多