retagged by
725 views
7 votes
7 votes
Consider a processor with a branch-if-equal instruction that is $32$ bits long$\textsf{: BEQ R12, R11, X.}$

$6$ bits are used to encode the opcode, $6$ bits are used to encode one register number, $6$ bits are used to encode another register number $\&\; 14$ bits are used to encode an unsigned offset that will be added to the program counter $(\mathrm{PC})$ if the branch ends up being taken, and a new instruction address is required.

The branch instruction is at memory location $5004$ (in decimal). All instructions are $4$ bytes long.

How many instructions away (the number of instructions) from the $\textsf{BEQ}$ instruction could we reach?
retagged by

3 Answers

2 votes
2 votes

​​​​​Instruction start address => 5004 

Instruction size => 4B

PC storing the next instruction address as => 5008.

Max. unsigned number possible with 14 bits (unsigned offset) =                                                            2^14 -1 => 16383   

Target address = PC + offset = 5008 + 16383 => 21391

In the question, it is asked to find the number of instructions from the 
BEQ instruction (i.e. Number of instructions possible from instruction 5004)  

(21391 – 5008 + 1) / 4B  => 4096.

Here, (21391-5008+1) is used to calculate the number of addresses present starting from 5008 to 21391. 

Therefore, the answer will be 4096.

1 votes
1 votes

Given:

14 bits are used to encode an "unsigned" offset

 Branch Instruction location:5004

PC value(while executing our branch instruction): 5008 (Note:any increment/decrement is always applied to this updated value )

so we can at Max jump: (2^14-1 )/ 4 =4095.75~ 4095 instruction away from "5008"(which is already one instruction away from our branch instruction ) 

so overall we can jump 4095+1=4096 instructions away from our branch instruction

Answer: