What's the difference between using ori and ad

2019-07-14 20:16发布

When I want to store a value in an address in MIPS, say the value 3 in $a0, I usually just use addi $a0, $0, 3. Sometimes I see people do this using ori $a0, $0, 3. Is one better than the other? What's the difference?

标签: assembly mips
1条回答
\"骚年 ilove
2楼-- · 2019-07-14 20:20

There are some subtle differences between the two:

ADDI:

  • Sign-extends the immediate.
  • Can result in integer overflow exceptions (can be avoided by using ADDIU instead).

ORI:

  • Zero-extends the immediate.
  • Not susceptible to integer overflow.
查看更多
登录 后发表回答