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?
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
.
User contributions licensed under CC BY-SA 3.0