(20 points) Suppose that $t1 has the binary value of 0011 1111 1111 1000 0000 00
ID: 641086 • Letter: #
Question
(20 points)
Suppose that $t1 has the binary value of
0011 1111 1111 1000 0000 0000 0000 0000
and $t0 has the binary value of
1010 1101 0001 0000 0000 0000 0000 0010
what will $t2 be after the completion of the following sequence of instructions?
slt $t2, $t0, $t1
beq $t2, $zero, ELSE
j DONE
ELSE: addi $t2, $zero, 2
DONE:
Suppose that the program starts at (byte) address 8 in the memory, convert the following MIPS code into binary code
slt $t2, $t0, $t1
beq $t2, $zero, ELSE
j DONE
ELSE: addi $t2, $zero, 2
DONE:
Explanation / Answer
Suppose that $t1 has the binary value of in 2’s compliment notation
0011 1111 1111 1000 0000 0000 0000 0000
and $t0 has the binary value of in 2’s compliment notation
1010 1101 0001 0000 0000 0000 0000 0010
what will $t2 be after the completion of the following sequence of instructions?
# value of $t1 > $t0 in 2’s compliment notation
slt $t2, $t0, $t1 # slt = set less than
# if $t0 < $t1 then $t2 = 1 else $t2 = 0 # since $t0 is < $t1, $t2 = 1
# slt $t1,$s2,$s3 # if $s2 < $s3, $t1 = 1 else $t1 = 0 # just another example
beq $t2, $zero, ELSE # beq = branch on equal
# if $t2==$zero then go to ELSE:
# $t2 = 1 hence it will NOT branch to ELSE
# $zero means zero register with value 0 = zero
j DONE # so the control will come here and jump to DONE label
ELSE: addi $t2, $zero, 2 # addi this does not get executed because $t2 = 1
DONE: # control comes here with the value of $t2 unaltered and = 1; $t2 = 1
After the completion of the above sequence of instructions, $t2 will be equal to 1 considering the two’s compliment in binary $t2 will be equal to 0001 as 0001 is the binary equivalent of decimal 1
The question had mentioned it as 2’s compliment in the comment 6 months ago. Hence getting the binary value after reversing the two’s compliment
And recalculating the result with 2’s compliment value
Since it said 2’s compliment in the comment after 6 months, repeating the same question with normal binary values and NOT 2’s compliment below – can be ignored if just 2’s compliment would suffice.
Suppose that $t1 has the binary value of
0011 1111 1111 1000 0000 0000 0000 0000
and $t0 has the binary value of
1010 1101 0001 0000 0000 0000 0000 0010
what will $t2 be after the completion of the following sequence of instructions?
# value of $t0 > $t1 ( we are NOT taking 2’s compliment here – just binary)
slt $t2, $t0, $t1 # slt = set less than
# if $t0 < $t1 then $t2 = 1 else $t2 = 0 # since $t0 is not < $t1, $t2 = 0 actually $t0 > $t1
# slt $t1,$s2,$s3 # if $s2 < $s3, $t1 = 1 else $t1 = 0 # just another example
beq $t2, $zero, ELSE # beq = branch on equal
# if $t2==$zero then go to ELSE:
# $t2 = $zero hence it will branch to ELSE
# $zero means zero register with value 0 = zero
j DONE
ELSE: addi $t2, $zero, 2 # addi = add immediate $t2 = $zero + 2 = 2
DONE:
After the completion of the above sequence of instructions, $t2 will be equal to 2 without considering the two’s compliment; in binary $t2 will be equal to 0010 as 0010 is the binary equivalent of decimal 2
Hence if you consider the two’s compliment the value of $t2 will be 1 else it will be 2
Suppose that the program starts at (byte) address 8 in the memory, convert the following MIPS code into binary code
slt $t2, $t0, $t1
0000 0001 0000 1001 0101 0000 0010 1010
# 0000 0001 0000 1001 0101 0000 0010 1010 is the binary equivalent of slt $t2, $t0, $t1
beq $t2, $zero, ELSE
0001 0001 0100 0000 0000 0000 0000 0000
# 0001 0001 0100 0000 0000 0000 0000 0000 is the binary equivalent of beq $t2, $zero, ELSE
j DONE
0000 10
# 0000 10 is the binary equivalent of MIPS j DONE
ELSE: addi $t2, $zero, 2
0010 0000 0000 1010 0000 0000 0000 0010
# 0010 0000 0000 1010 0000 0000 0000 0010 is the binary equivalent of addi $t2, $zero, 2
DONE:
Putting all the binary code together:
0000 0001 0000 1001 0101 0000 0010 1010
0001 0001 0100 0000 0000 0000 0000 0000
0000 10
0010 0000 0000 1010 0000 0000 0000 0010
$t0, $t1 and $t2 represent registers t0,t1 and t2
Results of multiplication and division will be stored in special registers Lo and Hi
mfhi and mflo means move form Hi and move from Lo