AVR XYZ寄存器 [英] AVR XYZ Registers

查看:386
本文介绍了AVR XYZ寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AVR微控制器中的Beatwean X,Y和Z寄存器有什么区别?它们各自适合C编译器做什么?编译器在哪里存储堆指针,堆栈指针,帧指针?该寄存器具有相同的功能还是在不同的空间(例如EEPROM,RAM)中提供寻址.

What is the difference beatwean X, Y and Z registers in AVR microcontrollers. What for each of them suitable in C compilers? And where do compilers store heap pointer, stack pointer, frame pointer? Do this registers have the same capabilities or providing addressing in different spaces(ex. EEPROM, RAM).

推荐答案

X Y和Z寄存器实际上是r27:r26,r29:r28和r31:r30寄存器对.它们每个都可用作指向SRAM的间接指针:

X Y and Z registers are actually pairs of r27:r26, r29:r28 and r31:r30 registers. Each of them can be used as indirect pointers to SRAM:

ld r16, X

后递增或前递减:

ld r16, -Y
st Z+, r16

但是只有Y和Z可以用于位移

But only Y and Z can be used with displacment

ldd r16, Y + 10
std Z + 5, r16

并且只有Z可以用于间接读取闪存,并且不存在预减量或位移量:

and only Z can be used to indirect read the flash memory, and no pre-decrement or displacement are available :

lpm r16, Z+
lpm r17, Z

因此,没有特别的方法可以使编译器使用它们,以及应该存储哪些信息.考虑所有这些限制,这在很大程度上取决于编译器. 例如,Z可以保留以访问闪存,而Y可以存储堆栈帧,因为可以通过位移来访问它. 同样,例如,GCC将X和Z寄存器用作由调用方保留",而Y寄存器用作由被调用程序保留".此约定有助于最大程度地减少推送操作,从而允许调用程序将Y分配为指针迭代器或堆栈框架,还允许被调用的例程自由使用X和Z,而无需花费时间来推送和弹出它们. 但是同样,如何使用这些寄存器在很大程度上取决于编译器.并没有强迫它以一种或另一种方式使用寄存器.

So, there is no particular way how compilers should use them, and what information there should be stored. It is very depend on the compiler, considering all those limitations. For example, Z is good to be reserved to access the flash memory, while Y is good to store the stack frame, because it can be accessible with displacement. Also for example, the GCC use X and Z registers as "preserved by the caller", while Y register is used as "preserved by the called routine". This convention helps to minimize push-pop operations, allowing the caller routine to allocate Y as a pointer iterator, or stack frame, and also allows the called routine to freely use X and Z without spending time to push and pop them. But again, how to use those registers is very depend on the compiler. Nothing force it to use registers in one way or another.

堆栈指针始终存储在SPH:SPL I/O寄存器(0x3E,0x3D)中,它们由内核本身处理,同时执行调用,返回,压入和弹出操作.编译器无需将其存储在其他位置.

The stack pointer is always stored in SPH:SPL I/O registers (0x3E, 0x3D) they are handled by the core itself, while performing calls, returns, pushes and pops. Compiler need not to store it somewhere else.

AVR中没有之类的东西.因此,如果编译器以某种方式实现堆内存管理,则取决于实现在何处以及如何分配堆.但是说到像AVR这样的小型MCU,通常根本没有必要存储堆,因为不需要动态分配.

There is no such thing as a heap in AVR. So, if compiler implements the heap memory management somehow, it depend on the implementation where and how the heap is allocated. But speaking of such small MCUs as AVR, there is usually no point to store heap at all, because no dynamic allocation is needed.

这篇关于AVR XYZ寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆