地址寄存器所需的位 [英] Bits required to address registers
问题描述
说我有12个寄存器.在机器代码指令中必须保留多少位才能寻址这12个寄存器中的任何一个?
Say I have 12 registers. How many bits must be reserved in the machine code instruction order to address any of these 12 registers?
推荐答案
在正常的固定宽度字段中,需要ceil(log2(12))
位对12种可能性中的1种进行编码.
It takes ceil(log2(12))
bits to encode 1 of 12 possibilities in a normal fixed-width field.
但是,少于2个寄存器的幂是否可以让我们在具有多个寄存器操作数的指令中保存任何位?是的,在这种情况下.
But does having fewer than a power of 2 registers let us save any bits in an instruction with multiple register operands? Yes, in this case.
3寄存器指令具有12^3 = 1728
可能的寄存器排列.但是使用3个单独的4位字段将为我们提供2^(4*3) = 4096
可能的编码.因此存在1个冗余位,因为2^11 = 2048
仍然大于1728.但是,将所有3个寄存器选择器编码为一个11位字段将需要更复杂的解码.
A 3-register instruction has 12^3 = 1728
possible permutations of registers. But using 3 separate 4-bit fields would give us 2^(4*3) = 4096
possible encodings. So there's 1 redundant bit, because 2^11 = 2048
which is still greater than 1728. However, encoding all 3 register selectors into one 11-bit field would require much more complex decoding.
2寄存器指令需要12^2 = 144
唯一的寄存器编码.但是在这里,2^(4*2) = 256
和下一个最低的2(128)次幂还不够大.
A 2-register instruction needs 12^2 = 144
unique register encodings. But here, 2^(4*2) = 256
, and the next lowest power of 2 (128) isn't big enough.
也许最好的选择是使用4位字段,并将13..15寄存器编码用于其他内容.例如转义代码,这意味着它实际上是不同的指令.或者,如果您不需要那么多的指令编码空间,请简化解码器,并保留冗余的指令格式.
Probably your best bet is to use 4-bit fields, and use the 13..15 register encodings for something else. e.g. an escape code that means it's actually a different instruction. Or if you don't need that much instruction coding space, simplify the decoders and leave your instruction format redundant.
或者最好的选择是拥有2的幂的寄存器,这样您就不会浪费编码空间.基本上每个现代的注册机都有2的幂的寄存器是有原因的.
Or really your best bet is to have a power-of-2 number of registers, so you don't waste coding space. There's a reason that basically every modern register machine has a power-of-2 number of registers.
这篇关于地址寄存器所需的位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!