CDA 3100 MAIN TIPS ANSWERS AND QUESTIONS
SET A+
✔✔Is it correct to write this instruction?
lw $s0, $s1($s0) - ✔✔No, number must be a constant
✔✔Is it correct to write this instruction?
add $s0, 100($s1), $s2 - ✔✔No, two numbers added must be registers, not from
memory
✔✔Suppose memory at address 1000 to 1027 are storing 1,2,...,8 (in each 4 bytes).
Suppose $t0 is 1000. What will be in $t0 after this instruction?
lw $t0, 16($t0) - ✔✔5
✔✔Suppose we have the address of A[i] in $t0, where A is an integer array. Write
instructions to swap A[i] and A[i+1]. - ✔✔lw $t1, 0($t0)
✔✔Where are instructions and data stored? - ✔✔BOTH are in memory
✔✔What does R-type mean?
I-type?
J-type? - ✔✔Register type
Immediate type
Jump type
✔✔Constants inside arithmetic operations so that they are much faster - ✔✔true
✔✔The immediate in andi, ori, and xori is treated as an unsigned ______ bit number -
✔✔16
✔✔Instruction NOR function - ✔✔If at least one of the bits is 1, the result is 0; use $zero
as one of the input operands (pseudoinstruction)
, ✔✔With these instructions, how can we load an integer value (like 100) into a register
($t0)? - ✔✔addi $t0, $zero, 100
ori $t0, $zero, 80
✔✔How to tell if $t0 is equal to $t1? Suppose you need to set $s0 to be 0 if they are
equal and any non-zero value otherwise - ✔✔Xor, sub, both will work
✔✔How to tell if $t0 is an odd number? Suppose you need to set $t1 to be 1 if so and 0
otherwise - ✔✔andi $t1, $t0, 1
✔✔How to tell if $t1 is no less than $t0?
Set $t2 to be 0 if $t1 is no less than $t0, otherwise 1 - ✔✔sub $t2, $t1, $t0
srl $t2, $t2, 31
✔✔Set $t1 to be 7 times $t0 in 2 instructions - ✔✔sll $t1, $t1, $t0
sub $t1, $t1, $t0
✔✔Suppose $t0 is storing 30, $t1 is storing 20. After the following instructions, what will
be the value in $t2?
sub $t2, $t0, $t1
srl $t2, $t2, 2
ori $t2, $t2, 10
(a) 8
(b)10
(c)18
(d) None of the above. - ✔✔B
✔✔Suppose word array A stores 0,1,2,3,4,5,6,7,8,9, in this order. Assume the starting
address of A is in $s0. After the following instructions, what will be the value in $t0?
addi $s0, $s0, 32
lw $t0, 4($s0)
andi $t0, $t0, 1
(a) 0
(b) 8
(c) 9
(d) None of the above. - ✔✔D
✔✔Assume A is an integer array with 10 elements storing 0,1,2,3,4,5,6,7,8,9. Assume
the starting address of A is in $s0 and $t0 is holding 3. After the running the following
code, what will be the content of $t0?
SET A+
✔✔Is it correct to write this instruction?
lw $s0, $s1($s0) - ✔✔No, number must be a constant
✔✔Is it correct to write this instruction?
add $s0, 100($s1), $s2 - ✔✔No, two numbers added must be registers, not from
memory
✔✔Suppose memory at address 1000 to 1027 are storing 1,2,...,8 (in each 4 bytes).
Suppose $t0 is 1000. What will be in $t0 after this instruction?
lw $t0, 16($t0) - ✔✔5
✔✔Suppose we have the address of A[i] in $t0, where A is an integer array. Write
instructions to swap A[i] and A[i+1]. - ✔✔lw $t1, 0($t0)
✔✔Where are instructions and data stored? - ✔✔BOTH are in memory
✔✔What does R-type mean?
I-type?
J-type? - ✔✔Register type
Immediate type
Jump type
✔✔Constants inside arithmetic operations so that they are much faster - ✔✔true
✔✔The immediate in andi, ori, and xori is treated as an unsigned ______ bit number -
✔✔16
✔✔Instruction NOR function - ✔✔If at least one of the bits is 1, the result is 0; use $zero
as one of the input operands (pseudoinstruction)
, ✔✔With these instructions, how can we load an integer value (like 100) into a register
($t0)? - ✔✔addi $t0, $zero, 100
ori $t0, $zero, 80
✔✔How to tell if $t0 is equal to $t1? Suppose you need to set $s0 to be 0 if they are
equal and any non-zero value otherwise - ✔✔Xor, sub, both will work
✔✔How to tell if $t0 is an odd number? Suppose you need to set $t1 to be 1 if so and 0
otherwise - ✔✔andi $t1, $t0, 1
✔✔How to tell if $t1 is no less than $t0?
Set $t2 to be 0 if $t1 is no less than $t0, otherwise 1 - ✔✔sub $t2, $t1, $t0
srl $t2, $t2, 31
✔✔Set $t1 to be 7 times $t0 in 2 instructions - ✔✔sll $t1, $t1, $t0
sub $t1, $t1, $t0
✔✔Suppose $t0 is storing 30, $t1 is storing 20. After the following instructions, what will
be the value in $t2?
sub $t2, $t0, $t1
srl $t2, $t2, 2
ori $t2, $t2, 10
(a) 8
(b)10
(c)18
(d) None of the above. - ✔✔B
✔✔Suppose word array A stores 0,1,2,3,4,5,6,7,8,9, in this order. Assume the starting
address of A is in $s0. After the following instructions, what will be the value in $t0?
addi $s0, $s0, 32
lw $t0, 4($s0)
andi $t0, $t0, 1
(a) 0
(b) 8
(c) 9
(d) None of the above. - ✔✔D
✔✔Assume A is an integer array with 10 elements storing 0,1,2,3,4,5,6,7,8,9. Assume
the starting address of A is in $s0 and $t0 is holding 3. After the running the following
code, what will be the content of $t0?