In: Computer Science
2. Write the hexadecimal numbers in the registers of $a0, $a1, $a2, $a3 after the following codes running:
ori $a0, $0, 11
ori $a1, $0, 19
addi $a1, $a1, -7
slt $t2, $a1, $a0
beq $t2, $0, label
addi $a2, $a1, 0
sub $a3, $a1,$a0
j end_1
label: ori $a2, $a0, 0
add $a3, $a1, $a0
end_1: xor $t2, $a1, $a0
*Values in $a0, $a1, $a2, $a3 after the above instructions are executed.
Ans->Values of registers in hexadecimal are :
$a0 =B
$a1=C
$a2=B
$a3=17
$t2=7
ori $a0, $0, 11 // do or of 0 , 11 and store the value in a0 register
ori $a1, $0, 19 // do or of 0 , 19 and store the value in a1 register
addi $a1, $a1, -7 // add the value of a1 register and -7 , and store the result in a1 register
slt $t2, $a1, $a0 // store 1 in t2 register if value in a1 register is less than value in a0 register ,else 0
beq $t2, $0, label // if t2 is equal to 0 then move to label else continue executing next instructions
addi $a2, $a1, 0 // add the value of a1 register and 0 ..and store the result in a2 ==>a2=a1+a0
sub $a3, $a1,$a0 // subtract the value of a0 register from a1 register and store the value in a3==>a3=a1-a0
j end_1 //this means jump to end_1 label
label: ori $a2, $a0, 0 // do or of value in a0 register and 0 ..and store the value in a2
add $a3, $a1, $a0 // add values of register a1 and a0 ..store the result in a3
end_1: xor $t2, $a1, $a0 // do xor of values in a1 and a0 ...store the result in t2
Execution of program:(Assume value stored in decimal)
after first step $a0=11
after second step $a1=19
after third step $a1=19-7=12
after fourth step $t2=0 ==>since $a1>$a0
after fifth step control goes to label ==>since condition is true
after label instruction execution $a2=11
after add instruction execution $a3=$a1+$a0= 12+11=23
after execution of end_1 label $t2=$a1 ^ $a0 = 12 ^11=7
Hence values in decimal are
$a0 =11
$a1=12
$a2=11
$a3=23
$t2=7
Converting into hexadecimal we get
$a0 =B
$a1=C
$a2=B
$a3=17
$t2=7