问题描述
我正在单周期MIPS处理器上做作业,对addiu指令有些困惑.
I am doing an assignment on single cycle MIPS processor and I am a little confused on the addiu instruction.
在此网站上,作为我的参考作者指出立即数将被扩展符号
On this website, as my reference the author states that the immediate will be sign extened
Description:
Adds a register and a sign-extended immediate value and stores the result
in a register
Operation:
$t = $s + imm; advance_pc (4);
Syntax:
addiu $t, $s, imm
Encoding:
0010 01ss ssst tttt iiii iiii iiii iiii
如果我有以下说明
lui $3,0x1001
addiu $3,$3,0x8010
然后创建我的数据路径,使符号扩展我会得到的
and I create my data path that sign extends addiu I would get
$3 := 0x1001_0000
$3 := 0x1001_0000 + 0x1111_8010 = 0x1000_8010
但是根据PCSpim的说法,这是不正确的,我应该得到
But it is incorrect according to PCSpim and I should get
$3 := 0x1001_8010
我感到困惑,为什么我需要对扩展addiu进行签名,据我了解,如果我执行addiu $1, $1, -10
之类的操作,则应将其视为addiu $1, $1, 10
,因为它是未签名的.
I am confused why I need to sign extend addiu, from what I understand if I do something like addiu $1, $1, -10
it should be treated as addiu $1, $1, 10
because it is unsigned.
那么为什么说我应该对立即数进行符号扩展?
So why does it say I should sign-extend the immediate value?
推荐答案
在spim
中,
addiu $3,$3,0x8010
是伪操作,并且由于addiu
指令不能[通过0x
]被识别为对 unsigned 的渴望.因为符号扩展名].
is a pseudo-op and recognized as a desire for unsigned addition [by virtue of the 0x
] which the addiu
instruction can't do [because of the sign extension].
因此,spim
生成:
ori $1,$0,0x8010
addu $3,$3,$1
在mars
中,顺序为:
lui $1,0
ori $1,$1,0x8010
addu $3,$3,$1
这篇关于MIPS ADDIU混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!