1

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

2 回答 2

2

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

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

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

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

于 2011-11-29T21:19:57.623 回答
-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
于 2015-11-09T05:22:56.413 回答