编写一个接受用户整数的MARIE程序,如果它是质数,则该程序将输出1,否则,该程序将输出0。示例:
如果用户输入为17,则输出为1
如果用户输入为15,则输出为0
可以帮我开发这个问题以获得答案
答案 0 :(得分:0)
这是代码:
Org 0
Input
Store A
Store Val2
Output
Subt one
jump testNeg
Loop, Load A
Subt Value
Skipcond 400
jump div
jump prime
div, Load Val2
Store A
if, Load A
Skipcond 400
jump else
jump prime
else, Skipcond 800
Jump Endif
Then, Load A
Subt Value
Store A
Jump if
Endif, Load Value
Add one
Store Value
jump div
testNeg, Skipcond 000
jump testZero
jump nonPrime
testZero, Skipcond 400
jump Loop
jump nonPrime
nonPrime, Load zero
Output
Halt
prime, Load Val2
Subt Value
Skipcond 400
jump nonPrime
Load one
Output
Halt
A, DEC 0
one, DEC 1
zero, DEC 0
Value, DEC 2
Val2, DEC 0