在R12中,我有以下在msp430程序集中否定某些整数值的版本:
inv R12
inc R12这是根据手册和我认为这将是一样的工作?
inv R12
add #1, R12但这会有效吗?为什么不呢?
sub #1, R12
inv R12这仍然是新的,感谢您的任何帮助!
发布于 2019-10-05 07:01:04
INC dst是用ADD #1, dst模拟的,所以前两个版本完全相同。
至于第三个版本:在两种补码表示中,反转所有位都会计算负减1,所以您正在计算( + 1)(−x−1)或−(−(x + 1) + 1 ),这确实是一样的。
如果你想要一个更实际的演示,就用暴力:
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
int main()
{
for (uint32_t i = 0; i < 0x10000; i++) {
uint16_t input = i;
uint16_t output1 = (~input) + 1;
uint16_t output2 = ~(input - 1);
assert(output1 == output2);
}
puts("it works!");
return 0;
}https://stackoverflow.com/questions/58242820
复制相似问题