LMC - 不陷入负面(小人电脑)

发布于 2025-01-04 03:09:47 字数 386 浏览 2 评论 0原文

刚刚在这里使用小人电脑,遇到了一个困扰我的问题。由于没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野生奥特曼 2025-01-11 03:09:47

我知道我会后悔这一点,但由于这看起来相当简单,我将在无法测试的情况下尝试这样做:-)

INP
STA DEC
INP
LOOP SUB DEC
BRP OUTPUT
ADD DEC             <-- we went negative, so add back once
HLT
OUTPUT OUT
BRA LOOP
DEC DAT

I know I'll regret this but since this seems fairly straight forward, I'll attempt this without being able to test :-)

INP
STA DEC
INP
LOOP SUB DEC
BRP OUTPUT
ADD DEC             <-- we went negative, so add back once
HLT
OUTPUT OUT
BRA LOOP
DEC DAT
皇甫轩 2025-01-11 03:09:47
INP
STA first
INP
LOOP SUB first
BRP yesrepeat
ADD one
HLT
yesrepeat OUT
BRA LOOP
first DAT
one dat 001
INP
STA first
INP
LOOP SUB first
BRP yesrepeat
ADD one
HLT
yesrepeat OUT
BRA LOOP
first DAT
one dat 001
北方的巷 2025-01-11 03:09:47
INP
STA DEC
INP
LOOP SUB DEC
OUT
BRP LOOP 
HLT
DEC DAT 
INP
STA DEC
INP
LOOP SUB DEC
OUT
BRP LOOP 
HLT
DEC DAT 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文