我不明白为什么以下相同的操作会报告两个不同的输出。当我的 num 被声明为负值并将 num 添加到 baseAddr 时,我看到我的 addr 超出了 32 位范围。另一方面,如果我将 num 声明为正值并进行减法,我确实看到了正确的结果。即我的结果输出被准确报告。有人可以解释一下下面的计算有什么问题吗?
/* Architecture is powerpc. Program cross-compiled for powerpc. Gcc Version- 4.6.2 */
#include <stdio.h>
typedef unsigned long long u_int64;
typedef unsigned long u_int32;
int main() {
u_int64 baseAddr = 0x8e008128;
u_int32 num = -360;
u_int64 addr = baseAddr + num;
printf("\nAddr 1st step = 0x%llx\n", addr);
/* Same operation, but slightly different */
num = 360;
addr = baseAddr - num;
printf("\nAddr 2nd step = 0x%llx\n", addr);
return 0;
}
/* Output:
Addr printed is 0x18e007fc0, but I need just 0x8e007fc0
/diagsk10copy/bin # ./e500GPR
Addr 1st step = 0x18e007fc0 //Wrong
Addr 2nd step = 0x8e007fc0
*/