2. Consider the below MIPS code snippet: 1: lui $t0, 0x0A0B 2: ori $t0, $t0, 0x0
ID: 2247951 • Letter: 2
Question
2. Consider the below MIPS code snippet:
1: lui $t0, 0x0A0B
2: ori $t0, $t0, 0x0C0D
3: sw $t0, 0($0)
4: lb $t0, 2($0)
(1). What’s the value of $t0 after line 1?
(2). What’s the value of $t0 after line 2?
(3). In a little-endian machine, what are the byte values at memory addresses 0x0, 0x1, 0x2, and 0x3 after line 3?
Byte value at address 0x0:
Byte value at address 0x1:
Byte value at address 0x2:
Byte value at address 0x3:
(4). In a big-endian machine, what are the byte values at memory addresses 0x0, 0x1, 0x2, and 0x3 after line 3?
Byte value at address 0x0:
Byte value at address 0x1:
Byte value at address 0x2:
Byte value at address 0x3:
(5). What’s the value of $t0 after line 4 in a little-endian machine? What’s the value of it in a big-endian machine?
In a little-endian machine:
In a big-endian machine:
Explanation / Answer
2.1) LUI instruction :
Load Upper Immediate - load upper 16 bit of given register immediately with the given value and sets lower 16 bit as zeros
here LUI $t0,0x0AoB - $t0 is the register and 0x0AoB(hexadecimal)=2571(decimal)=0000101000001011(binary)
therefore, the value of $t0 is 0000101000001011 0000000000000000
2.2) Lower Order immediate:
Lower Upper Immediate and add - load lower 16 bit of given register immediately with the given value and add with previous value of register
ORI $t0,$t0,0x0C0D - $t0 is the register and 0x0C0D(hexadecimal)=3085(decimal)= 0000110000001101(binary) is loaded to lower 16 bits
therefore, the value of $t0 is 0000101000001011 0000110000001101
3) sw -store word command
sw $t0 , 0($0) - this command is used to store a value from register to a memery
based on the type of endian machine used (ie, little or big)- the value is stored from msb or lsb
IN LITTLE-ENDIAN Machine
the least significant value is stored in the lower memory address as follows
the value in $t0 = 1010000010110000110000001101 = 168496141 = 0x0A0B0C0D
Byte value at address 0x0: 0x0D
Byte value at address 0x1: 0x0C
Byte value at address 0x2: 0x0B
Byte value at address 0x3: 0x0A
4.) IN BIG ENDIAN Machine
the most significant value is stored in the lower memory address as follows
the value in $t0 = 1010000010110000110000001101 = 168496141 = 0x0A0B0C0D
Byte value at address 0x0: 0x0A
Byte value at address 0x1: 0x0B
Byte value at address 0x2: 0x0C
Byte value at address 0x3: 0x0D
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.