MIPS ADDIU confusion

不羁岁月 提交于 2019-12-08 11:58:10

问题


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

If I have the following instructions

   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

But it is incorrect according to PCSpim and I should get

$3 := 0x1001_8010  

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?


回答1:


In spim, the:

addiu    $3,$3,0x8010

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].

So, spim generates:

ori    $1,$0,0x8010
addu   $3,$3,$1

In mars, the sequence is:

lui    $1,0
ori    $1,$1,0x8010
addu   $3,$3,$1


来源:https://stackoverflow.com/questions/38451154/mips-addiu-confusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!