assembly - 有时会给出错误的答案
问题描述
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
解决方案
你的论点倒退了。你的结果2**3
和3**2
只是倒退。2**2
并且2**4
不受参数顺序的影响。
不可能8**8
用 16 位数字表示,因为那是0x1000000
,所以你总是会得到错误的结果。
您的代码首先采用指数,然后是基数。
我使用**
exponent 的约定而不是^
,因为后者在大多数编程语言中用于表示异或。
推荐阅读
- c++ - 带有两个视频适配器的笔记本电脑上的 Directx 游戏,错误的一个连接了输出
- unity3d - 如何使用 Physics2D.raycastAll
- javascript - 如果真或假,希望过滤数组并根据标志将它们变成 2 个数组
- ionic-framework - 离子原生插件未同步显示错误:您必须自己安装对等依赖项
- javascript - ajax-如何获取我的用户名的值?
- c - 合并指针字符串时需要指针操作数
- java - Google 的 ID 令牌使用 Firebase for Android 登录
- python - '?' 是什么意思?在下面的 Python 列表代码中是什么意思?
- ios - 是否可以突出显示 tableView 单元格内的文本子字符串?
- javascript - 如果不存在合适的 ARIA 属性,我应该使用自定义 ARIA 属性吗?