[英]how to use negative numbers as one in assembly?
I have a arithmetic program in assembly, but when i add, subtract, multiply negative numbers, it will not result in desired output. 我在汇编中有一个算术程序,但是当我加,减,乘正数时,它不会产生所需的输出。
For Example 例如
input: 输入:
-1+2=66675 (should be 1)
-1-1=656745 (should be -2)
-1*-1=66757 (should be 1)
Questions: 问题:
how would i treat (-) and (1) as one? 我将如何对待( - )和(1)?
how to do arithmetic operation in signed numbers? 如何用有符号数进行算术运算?
any advice please ... 任何建议请...
I recommend reading up on 2's compliment and the difference between signed and unsigned ints. 我建议阅读2的赞美以及有符号和无符号整数之间的区别。 The value you are showing looks suspiciously like a signed int negative value being translated into an unsigned int value without doing a conversion. 您显示的值看起来很可疑,就像有符号的int负值被转换为unsigned int值而不进行转换。 Negative ints have a Most Significant Bit that is set to 1. If you shove that value into an unsigned int without first masking then you get a much larger number then expected. 负的int有一个设置为1的最高位。如果你在没有第一次屏蔽的情况下将该值推送到unsigned int,那么你会得到一个比预期更大的数字。
Example in a 8 bit representation: 8位表示的示例:
signed value = -1
unsigned value = 255
binary = 1111 1111
Take the twos compliment:
1111 1111
XOR 0000 0000
equals 0000 0000
add1 0000 0001
dec value = 1
You can learn more here (They have an example for two's compliment addition you can look at): http://academic.evergreen.edu/projects/biophysics/technotes/program/2s_comp.htm 你可以在这里了解更多(他们有一个你可以看到的两个赞美补充的例子): http : //academic.evergreen.edu/projects/biophysics/technotes/program/2s_comp.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.