In: Computer Science
The following code segment is stored in memory starting at memory location 0x00445670.
What are the two possible values for the contents of the PC after the branch instruction has executed?
bgez $a0, skip # mem location: 0x00445670
subu $s2, $s1, $t0 # branch NOT taken (false)
ori $v0, $t1, 0x0003 #
skip:
addi $t0, $t1, 2 # branch taken (true)
if taken:
if not taken:
Hint: Remember how many bytes each instructions takes.
bgez $a0, skip # mem location: 0x00445670
subu $s2, $s1, $t0 # branch NOT taken (false) # mem location: 0x00445674
ori $v0, $t1, 0x0003 # mem location: 0x00445678
skip: # mem location: 0x004457c
addi $t0, $t1, 2 # branch taken (true) # mem location: 0x00445680
BGEZ : Branch if the register is greater than or equal to zero.
in this instruction the operation will be perform are :
instruction syntax : BGEZ $a0 , offset
here we have skip as offset
if ( $a0 >= 0)
advance_pc(offset<<2)
pc = pc + (4<<2)
pc = 0x00445670 + (in binary 4 = 100 << 2)
pc = 0x00445670 + (in binary = 10000 = 0x10)
pc = 0x00445680
else
advance_pc(4)
meaning pc += 4
pc = 0x00445674