This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
我尝试 使用一个小函数 来确定我的应用程序在运行时使用了多少栈空间。
我遇到的一个重大问题是、当我读取 SP/R1时、这个值就没有意义了。 它返回报告>128k。 纵观所有32位、它显示的值远超过1M、这对于该器件是错误的、因为它具有128KB 的板载 FRAM。
相关的代码片段
```μ A
一些不良数据的示例会很有帮助。
我看到 GCC 包含一个字大小的版本:
#define _get_SP_register() \ ({ \ unsigned int __x; \ __asm__ __volatile__( \ "mov SP, %0" \ : "=r" ((unsigned int) __x) \ :); \ __x; \ })
将其全部删除并重试后、执行以下操作
uintptr_t sp_value; // Using the `movx` instruction to handle 20-bit addressing in large memory model __asm__ __volatile__("movx.a SP, %0" : "=r"(sp_value) : : "memory"); uint32_t stack_pointer = (uint32_t)sp_value;
可以可靠地工作。
之后转换到 uint32_t 是为了获得简单/已知的格式与 uintptr_t 个人偏好。
似乎数据类型本身的大小必须为 uintptr_t、而不是任何任意值。