【发布时间】:2021-08-07 18:33:34
【问题描述】:
每当我运行程序时,为x 输入 2 为y 输入 2 会得到 4,这很好,但每当我输入 2 的 3 次幂时,它会输出 9 什么时候应该输出 8 什么时候我做 3 到 2 的幂,它应该给 9 时输出 8。它适用于 2^2、2^4 但不适用于 2^3。 8^8 也给出256。程序写错了吗?
/ 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 Count
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
【问题讨论】:
-
您是否考虑过 2^4 == 4^2 并且您只是在计算 a^b 而不是 b^a?对于适合 32 位但不适合 16 位的 8^8,我无法想象溢出的来源——除非您返回的是高 16 位。
标签: assembly exponentiation marie