In: Computer Science
Suppose the address of the first instruction is 5F370654 in hexadecimal in the following code. Show in decimal the immediate value (i.e. offset) in the beq and bne instruction, and in hexadecimal (of 7 digits) the psedudo address in the j instruction. Separate the numbers by comma.
label1: beq $t1, $t2, label3 (17 instructions here) label2: bne $t3, $t4, label1 (46 instructions here) label3: j label2
label1:
beq $t1, $t2, label3
(17 instructions here)
label2:
bne $t3, $t4, label1
(46 instructions here)
label3:
j label2
Address of first instruction = 0x5F370654
Address of Label2 = 0x5F370654 + (18*4) = 0x5F370654 + 0x48 =
0x5F37069C
Address of Label3 = 0x5F370654 + (65*4) = 0x5F370654 + 0x104 =
0x5F370758
Number of instructions between beq $t1, $t2, label3 and label 3 =
(17 + 47) = 64
offset = 64
other
Method: When instruction beq $t1, $t2, label3 is
executing, value of PC = (0x5F370654 + 4) = 0x5F370658
Address of label3 = 0x5F370758
offset = (0x5F370758 - 0x5F370658)/4 = 0x100/4 = 256/4 = 64
Number of instructions between bne $t3, $t4, label1 and label 1
= 18
offset = -(18 + 1) = -19
other
Method: When instruction bne $t3, $t4, label1 is
executing, value of PC = (0x5F37069C + 4) = 0x5F3706A0
Address of label1 = 0x5F370654
offset = (0x5F370654 - 0x5F3706A0)/4 = -(0x4c)/4 = -76/4 = -19
Hexadecimal (of 7 digits) the psedudo address in the j
instruction.
Address of Label2 = 0x5F370654 + (18*4) = 0x5F370654 + 0x48 =
0x5F37069C
(F37069C)>>2 = 0x3cdc1a7