-1

x每当我运行程序时,为2输入 2y会得到 4,这很好,但是每当我输入 2 的 3 次方9时,它应该输出 8,当我输入 3 的 2 次方时,它会输出 8应该给出 9。它适用于 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

4

1 回答 1

2

你的论点倒退了。你的结果2**33**2只是倒退。2**2并且2**4不受参数顺序的影响。

不可能8**8用 16 位数字表示,因为那是0x1000000,所以你总是会得到错误的结果。

您的代码首先采用指数,然后是基数。


我使用**exponent 的约定而不是^,因为后者在大多数编程语言中用于表示异或。

于 2021-05-18T14:30:07.943 回答