Difference between Sign-extends the immediate vs Zero-extends the immediate

0

To my understanding:

Zero-extends the immediate- will pad the immediate with zeros from left, so:

   ori $t1, $0, 0xF

result:

    0x0000000F

Sign-extends the immediate - will pad the immediate with the most significant bit, so:

    addi $t1, $0, 0xF

result:

   0xFFFFFFFF

I am obviously wrong, but why?

assembly
mips
asked on Stack Overflow May 30, 2017 by Gigalala • edited May 30, 2017 by old_timer

1 Answer

2

You need to consider the size of the immediate, which is 16 bits in mips. Thus your immediate is actually 0x000F and so the MSB is zero. To illustrate sign extension to negative, use a bigger immediate that has bit #15 set, such as 0xffff which will indeed be interpreted by the cpu as 0xffffffff.

answered on Stack Overflow May 30, 2017 by Jester

User contributions licensed under CC BY-SA 3.0