LMC - 不陷入负面(小人电脑)
刚刚在这里使用小人电脑,遇到了一个困扰我的问题。由于没有 if 等,我发现很难阻止奇数在从偶数中减去时变成负数。例如,我在循环中从 10 取 3,并在零处分支。但这永远不会为零。所以我想知道如何让应用程序在变为负值之前停止,例如在循环中从 10 减去 3 将是 10, 7, 4, 1, -2。但我希望它停在 1,因此不会变成负数并克服这个问题。
这是我到目前为止所拥有的,并且仅适用于偶数和偶数:(
INP
STA DEC
INP
LOOP SUB DEC
OUT
BRZ QUIT
BRA LOOP
QUIT HLT
DEC DAT
首先,我想将第二个输入声明为变量是一个好主意,对吗?或者不是?)
将不胜感激如果你能帮我的话。并想出一个永久的解决方案。
Just working with Little Man Computer here and have ran into a problem that is kind of bugging me. Since there is no if's etc, I'm finding it hard to stop odd numbers going into negatives numbers when being subtracted from an even number. For example I take 3 off 10 in a loop and branch of at zero. But that never hits zero. So I want to know how to get the app to stop before it goes into negative, for example 3 subtracted from 10 in a loop will be 10, 7, 4, 1, -2. But I want it to stop at 1, therefore not going into negative and overcoming this problem.
This is what I have so far, and only works for even and even numbers:
INP
STA DEC
INP
LOOP SUB DEC
OUT
BRZ QUIT
BRA LOOP
QUIT HLT
DEC DAT
(to start off, I guess it would be a good idea to declare the second input as a variable, right? Or not?)
It would be greatly appreciated if you could help me out. And come up with a permanent solution to this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道我会后悔这一点,但由于这看起来相当简单,我将在无法测试的情况下尝试这样做:-)
I know I'll regret this but since this seems fairly straight forward, I'll attempt this without being able to test :-)