使用玛丽模拟器划分



我很难弄清楚玛丽模拟的划分。我不想要 -1,但它一直显示负数。我只想要它最多 2 个。有什么建议吗?

这是我的代码:

ORG 100
Input 
Store   x
Input   
Store   y
loop, load x
Subt    y
Store   x
Load    x
Output
Skipcond 0
Jump    loop
Load    x
Halt
x,  Dec     0 
y,  Dec     0 

输出:11852-1

我注意到,如果程序在除法时遇到余数,上面的一些响应会创建无限循环。我解决了这个问题,我的程序分别输出 2 个十进制值的结果和其余值。

这是一个非常古老的职位,但希望这对任何新来的议会有用。

STORE x
INPUT
STORE y
loop, Load x
If, Subt y
    Skipcond 000
    Jump Else
Then, Jump Endif
Else, Store x
    Load Counter
    Add One
    Store Counter
    Jump loop
Endif, Load Counter
Output
Load x
Output
HALT
x, Dec 0
y, Dec 0
Counter, Dec 0
One, Dec 1

//下面的代码修复了您的问题,但每当除法问题有余数时,就会创建一个无限循环。

ORG 100
INPUT
STORE x
INPUT
STORE y
loop, LOAD x
SUBT y
STORE x
SKIPCOND 000
OUTPUT
SKIPCOND 400
JUMP loop
HALT
x, Dec 0
y, Dec 0

试试这个:

Input 
Store   x
Input   
Store   y
loop, load x
Subt    y
Store   x
Load    x
Output
Skipcond 400
Jump    loop
Load    x
Halt
x,  Dec     0 
y,  Dec     0
ORG 100

input
store var1
input
store var2
loop, load var1
Subt var2
Store var1
Store remain

load qout
Add one
Store qout
Load remain
Subt var2
Skipcond 000
Jump loop

load qout
output
load remain
output
halt

var1, dec 0
var2, dec 0
one, dec 1
remain, dec 0
qout, dec 0

最新更新