Thursday, September 12, 2019

CS2100: Tutorial 3

Tutorial 3

Q1
a)
Load Upper immediate (LUI) $t0, 0xFF
OR $s0, $s0 , $t0

We load upper immediate because we cannot apply ori on the first 16 bits. Ori is i format and only takes 16 bits but the one we want is 32 bits.

b)
XORI $s0, $s0, 0xFF00
If its different, its true 
if its the same, its false

c)
andi $t0, $s0, 0xFF
//this is to mask it first because to shift we dont want to affect the other bits when we shift it
xor $s0, $s0, $t0 //we can clear the zero bits here because its the same
srl $t0, 1
//We can shift right shift left to clear the bits but its too much step 
or $s0,$s0,$t0

Q2
a)
addi $t2, $zero,2
div $t1, $r2
MFLO $t1 

b)
srl $t1,$t1,1
For signed, if there's a 4 bit number (1110) and we shift right, it will extend the sign

c)
Yes.

Q3
a) srl $s4, $s4, 1
b) lw $t1, 0($t0)
c) slt $t9, $t1, $s1 //sne $t9,$s1,$t1 (Check if its equal)
beq $t9, $zero, equal
d) j end
e) j loop

Q4
a)
1. $t1 = 108
$s1 = 108
$t0 = 124

2. $t1 = 104
$s1 = 108 + 104 =212
$t0 = 100

3. $t1 = 120
$s1= 212 + 120 = 332
$t0 = 132

//we jump one blcok each time
b) memory address for 104 should change to 0
c) Linked list

No comments:

Post a Comment