简体   繁体   中英

What's the difference between using ori and addi to initialize a value in MIPS?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM