如何将MARIE中的数字x提高到y的幂



我正在尝试创建一个MARIE程序,该程序将数字(x(提升为幂(y(并提供输出。我已经试过很多次改变我心中的想法,但我仍然面临着错误。下面的代码是我最接近解决这个问题的

INPUT
STORE X
STORE XNUM
INPUT
STORE Y
MULTIPLIERA,LOAD PROD
ADD X
STORE PROD
LOAD XNUM
SUBT ONE
STORE XNUM
SKIPCOND 400
JUMP MULTIPLIERA
JUMP NEWPRODUCT
NEWPRODUCT, LOAD X
STORE XNUM
LOAD PROD
STORE X
LOAD Y
SUBT ONE
STORE Y
SKIPCOND 400
JUMP MULTIPLIERA
LOAD PROD
OUTPUT
HALT          
X, DEC 00
XNUM, DEC 00
Y, DEC 00
ONE, DEC 01
PROD, DEC 00
3^2 gives me a 36 and 1^3 gives me a 4
/ Start of the main program 
Input / Enter the exponent Store y
Subt One
Store Count
Input / Enter the Base
Store x
Store y
Jns Exp
/ Ending the main program
Load Ans 
Output 
End, Halt
Exp, Hex 0
Loop2, Load Count
Skipcond 800
JumpI Exp
JnS Multiplier
Load Ans
Store x
Load Count
Subt One
Store Counter
Jump Loop2
/ Start of the subroutine Multiplier
Multiplier, Hex 0
Load Zero
Store Ans
Loop, Load x
Skipcond 800
JumpI Multiplier
Load Ans
Add y
Store Ans
Load x
Subt One
Store x
Jump Loop
/ Declaration
x, Dec 2
y, Dec 3
Zero, Dec 0
One, Dec 1 
Ans, Dec 0 
Count, Dec 0

这应该行得通。如果你对此有任何问题,请告诉我。

最新更新