在2的补码世界中,可以通过取1的补码(所有位反转)并加1来获得整数的否定.例如,在8位世界中:
A: 0x00000002 ; my number
~A: 0xFFFFFFFD ; 1's complement of my number
-A: 0xFFFFFFFE ; 2's complement of my number (negative A)
要减去A-B,我们肯定可以添加负数A(-B):
NOT B ; invert each bit in the 8-bit value, B
ADD B, 1 ; add 1, giving the 2's complement negated B
ADD A, B
当然,在我添加它之前,我必须修改B(否定它).如果我希望B保持完整怎么办?
PUSH B ; save B
NOT B ; invert each bit in the 8-bit value, B
INC A ; add 1, giving the 2's complement negated B
ADD A, B
POP B ; restore B
要么
NOT B ; invert each bit in the 8-bit value, B
INC A ; add 1, giving the 2's complement negated B
ADD A, B
NOT B ; restore B
这样才行.但是只有SUB指令会不会更容易?
SUB A, B
如果你正在编写汇编语言来做很多算术,你更喜欢哪种方法?而且,在第一种情况下,我使用了INC A指令.我可以在没有INC的情况下离开并且只使用ADD A
最后
以上就是等待斑马最近收集整理的关于c语言中sub是什么指令,汇编 – SUB指令的目的是什么?的全部内容,更多相关c语言中sub是什么指令,汇编内容请搜索靠谱客的其他文章。
发表评论 取消回复