简体   繁体   English

AVR汇编为什么LDI指令只能使用R16-R31寄存器

[英]AVR Assembly why does LDI instruction can only use R16 - R31 registers

Hello I came across this exam question in a past paper and I am baffled, so far no research has given me a conclusive answer as most people just say its a limitation of the processor.您好,我在过去的论文中遇到了这个考试问题,我很困惑,到目前为止,还没有研究给我一个确凿的答案,因为大多数人只是说这是处理器的限制。 I am very sure we did not cover this in class.我很确定我们没有在 class 中介绍这一点。

Does anyone know why?有谁知道为什么?

The simple answer is that LDI is just supported for the upper 16 registers.简单的答案是高 16 个寄存器只支持LDI

When you have a look at the ISA (instruction set architecture) you'll notice that the same applies to SUBI , SBCI , ANDI , ORI and CPI , each of which needs 12 bits in the opcode table: 8 bits for the 8-bit immediate and 4 bits to encode which of R16... R31 is the destination.当您查看 ISA(指令集架构)时,您会注意到这同样适用于SUBISBCIANDIORICPI ,其中每个都需要操作码表中的 12 位:8 位为 8 位立即数和 4 位来编码 R16... R31 中的哪一个是目的地。 This means that just to provide these 6 instructions with immediate, you are already occupying 37.5% of opcodes.这意味着,仅仅提供这 6 条指令,就已经占用了 37.5% 的操作码。

Supporting R0... R31 would require 75% of opcode just for 6 instructions: All AVR opcodes are 16-bit opcodes (except LDS , STS , CALL , JMP which are 32 bit), and you can only encode so much instructions with 16 bits支持 R0...R31 需要 75% 的操作码仅用于 6 条指令:所有 AVR 操作码都是 16 位操作码(除了 32 位的LDSSTSCALLJMP ),您只能用 16 位编码这么多指令位

Take for example the following 2-reg instructions: ADD , ADC , SUB , SBC , CP , CPC , AND , OR , EOR , LSR , ASR , ROR , MOV .以以下 2-reg 指令为例: ADDADCSUBSBCCPCPCANDOREORLSRASRRORMOV Each of these 13 instructions occupies 2^(5+5) opcodes because each one has to encode one of 2^5 possible source resp destination registers, summing up to more than 20% of opcode space.这 13 条指令中的每一条都占用 2^(5+5) 个操作码,因为每条指令都必须对 2^5 个可能的源寄存器和目标寄存器中的一个进行编码,总计超过 20% 的操作码空间。 And we did not yet consider jumps ( RJMP , RCALL , branches) or memory accesses like LDD , STD , IN , OUT .而且我们还没有考虑跳转( RJMPRCALL 、分支)或 memory 访问,如LDDSTDINOUT

Terminology: "opcode" above means all the bits needed to encode one specific machine instruction.术语:上面的“操作码”是指编码一条特定机器指令所需的所有位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM