我是 ARM 实验的新手,我对该处理器中的数据概念有疑问。 我遇到了麻烦。有检查计时器间隔的代码:
// get the current timer 0 count
unsigned long Timer0_GetTimestamp(void)
{
return T0TC;
}
// check to see if a timestamp is in the past
// returns 1 if in the past, 0 if not
int Timer0_TimestampExpiredCk(unsigned long timestamp)
{
unsigned long now = T0TC;
if (now > timestamp)
{
if ((now - timestamp) < 0x80000000)
return 1;
else
return 0;
}
else
{
if ((timestamp - now) >= 0x80000000)
return 1;
else
return 0;
}
}
// pause for a specific number of milliseconds
void Timer0_Delay(unsigned long milliseconds) {
unsigned long timestamp = Timer0_GetTimestamp() + milliseconds;
while (!Timer0_TimestampExpiredCk(timestamp));
}
我对数字“0x80000000”有疑问。我们应该将此数字视为 2 的补码还是二进制? 据推测,当两个变量之间的差异为零时,我们更改标志。如果我错了,请纠正我。
谢谢
最佳答案
(你的问题与ARM无关,是语言问题)
你想要这个数字是多少?你可以指定它 0x8000000UL 将使它成为一个无符号长是吗?
顺便说一句,如果您想要 0x80000000 作为无符号长整数,那么您也可以只查看现在时间戳结果的 msbit
if((now-timestamp)&0x80000000)
return 0;
else
return 1;
而且那里没有歧义。
或
return (~(now-timestamp))>>31;
如果 unsigned long 是 64 位,则可能需要在其末尾添加 &1,如果 unsigned long 是 32 位则不需要。
关于c - ARM 处理器中的数据存储方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11622936/