Given t00xBEADFEED what is the value of t2 for the following
Solution
The value of $t2 after the following sequence is 0xEADFEED0
Explaination is as below:
$t0 = 0xBEADFEED
$t0 -$t9 are the registers. In this code 2 registers are used . These are $t0 and $t2
0x indicates it is a hexadecimal no.
sll - Shift Left Logical
sll d,s,shift
d-destination, s-source
Source is 10111110101011011111111011101101
Shift by 1 is as below
01111101010110111111110111011010 discard the high order bit, move each bit to the left and the low order bit is replaced by 0
Shift by 4 will be discard the high order 4 bits, move each bit to the left by 4 positions and replace lower order 4 bits by 0.
0xBEADFEED is the source.
As each of the hex number requires 4 bits, in this case the shifting means simply discard the high order hex number, move each one to left and replace lower order hex number by 0.
So the solution after the
sll $t2, $t0, 4
is $t2=0xEADFEED0
andi d,s,const
andi $t2, $t2, -1
-1 is written as all 1s in binary or all F in hex
11101010110111111110111011010000
11111111111111111111111111111111 (All 1s for value -1 )
-------------------------------------------------
Gives the original no. as AND with 0 results in 0 and AND with 1 results in the same no.
$t2=0xEADFEED0
0xFFFFFFFF (AND with -1)
---------------------------------------------
$t2=0xEADFEED0 results in the same number when Logical AND is done with all 1s
