加载32位常量以在MIPS中注册 [英] Load 32-bit constant to register in MIPS
问题描述
我在学习MIPS时对这部分感到困惑.
I was confused about this part while I study MIPS.
约翰·轩尼诗(John L. Hennessy)所写的教科书说,如果我们得到一些大常量要加载,我们应该
The textbook written by Professor John L. Hennessy say if we get some big constant to load, we should
lui $s0, upper(big)
ori $s0, $s0, lower(big)
但是我们为什么不做
addi $s0, $zero, big
由于寄存器是32位的,因此更加简单明了,不是吗?
Since the registers are 32-bit, this is more strightforward, isn't it?
推荐答案
传递给addi
的直接参数只有16位.要加载超出16位值范围的32位立即数,您需要分两次执行,如教科书中的示例所示.
The immediate argument passed to addi
is only 16 bits. To load a 32-bit immediate value that is outside the range of a 16-bit value you need to do it in two goes, as in the example from your text book.
(预料到另一个问题,之所以没有采用32位立即值的立即加载或立即添加指令,是因为MIPS ISA使用固定大小32位指令,因此任何指令参数总是< 32位可用-这在RISC体系结构中非常常见.)
(Anticipating a further question, the reason there is no load immediate or add immediate instruction which takes a 32-bit immediate value is because the MIPS ISA uses fixed size 32-bit instructions, so there are always < 32 bits available for any instruction arguments - this is very common in RISC architectures.)
这篇关于加载32位常量以在MIPS中注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!