c - ARM 处理器中的数据存储方式

标签 c arm

我是 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/

相关文章:

c - 如何在risc-v中实现printf函数?

c - 管理 C 中的代码变体 : changing variable that repeats all over the code

c - 来自文件系统的 "short read",什么时候会发生?

c - C 函数调用的 ARM 汇编函数中的寄存器使用情况

c++ - 使用 GCC 编译 FreeRTOS,使用 G++ 编译应用程序代码

c++ - 未创建 Keil uVision5 .axf 文件

c - strtok() 函数自动忽略不是我的分隔符的数据

c - while 循环内的 scanf() 错误处理?

c - ARM汇编中的矩阵乘法

c++ - 如何为 MinGW 用户安装 gcc-arm-none-eabi?