The Gateway to Computer Science Excellence
+36 votes
Consider a RISC machine where each instruction is exactly $4$ bytes long. Conditional and unconditional branch instructions use PC-relative addressing mode with Offset specified in bytes to the target location of the branch instruction. Further the Offset is always with respect to the address of the next instruction in the program sequence. Consider the following instruction sequence$$\begin{array}{ll} \text{Instr. No.} & \text{Instruction} \\\hline  \text{i:} & \text{add R2, R3, R4} \\   \text{i+1:} & \text{sub R5, R6, R7} \\  \text{i+2:} & \text{cmp R1, R9, R10}  \\ \text{i+3:} & \text{beq R1, Offset}  \\ \end{array}$$If the target of the branch instruction is $i,$ then the decimal value of the Offset is ____________ .
in CO and Architecture by
edited by | 5.3k views
@Arjun Sir

For some reason the question is not visible on my screen..It is happening with a lot of questions..Has anyone else also experienced the same?
question is to be uploaded only..
I kept -4 in the exam :(
same for me also
@arjun sir, In gateoverflow mock interface when I was giving GATE 2017 SET 1 Paper, the questions were not well visible, options were not separated with entering[new line], everything was in like 1 paragraph including options.
What should the correct answer actually be ?

Should it be 16 or -16 ?

I am asking this since the question asks us to give the decimal value of the Offset.


PC relative addressing mode = PC + offset

if you keep +16, you will forward to 4th instruction from PC

if you keep -16, you will backward to 4th instruction from PC

Pls check if this reasoning is correct or not:

Every instruction is 4B long. There are 4 instructions. Offset wants to refer to the beginning while it is at the end so it has to go back 16B (4B X 4) as the offset is in Bytes (as per Q).

So the offset stores (-16) because PC has to add this value to get there.

For better understanding of the Instruction Set Architecture this is a good read:


 Arjun , please provide " comments collapsed by deafult "  in this site

Only for questions or for answers too?

 Arjun , for answers too.

Also instead of collapsing all comments, there could be 1  or 2 comments with "more comments" button. Thanks.

Okay. Will consider it in next update. But that's an entirely client stuff so you can also make a plugin and add to your browser for that purpose.

3 Answers

+39 votes
Best answer

Answer is -$\bf{16.}$

Program Counter is updated with the address of next instruction even before the current instruction is executed.

That is why the question says that the address of the next instruction is updated with next instruction in sequence.

Before executing instruction $\bf{i + 3}$, the current state looks as under:

Please note: BEQ instruction is for Branch Equal

Question says that the target of branch instruction is 'i' which is at $2000$ in our example.

So, we need to go to address $\bf{2000}$ from address $2016$ (which is currently pointed by PC)

$\bf{2016 - 2000 = 16}$

So, we have to specify Offset as -$16$ which would mean that $16$ should be subtracted from next address instruction ($2016$).

edited by

So, we have to specify Offset as -16 which would mean that 16 should be subtracted from next address instruction (2000).

I think its a typo. Shouldn't it be 2016 ? 

what does cmp R1,R9,R10 DOES?


no need to bother about it, it doesn't need to solve this question, that's why they didn't defined it !

+16 votes

assume addresses start with $2000$ for the first instruction.

$2000---\text{add }R2,R3,R4$

$2004---\text{sub }r5,r6,r7$


$2012---\text{beq } r1,$offset  //pc after instruction fetch of this instruction will be $2016$,
and branch target is $2000,$offset will be $(2016-16)=2000$

$2016$------next instruction
edited by
yup i did same..i think its correct as nothing mentioned so byte addressable

See in question"offset in bytes".it should be correct.

yes i am also saying its correct only... :)
offset is address of next instruction in program sequence.

what will be next instruction here?

i+1 or when again control comes back to i
@Srestha,i didn't get you.So i try to simplify it.

When processor is executing instruction on 2012 at that time pc will contain value 2016 which is address of next instruction to be executed in a serial way.

But instruction at address 2012 is branch instruction whose target is 2000.

So,we want to branch at address 2000,and currently pc contain address 2016,in that way value of offset is -16 with respect to pc.


Hope it clear your doubt.
that I understood

I mean

u r telling in address 2000- one instruction started

in 2004-same instruction, 2008-same instruction,2012-same instruction.

then in 2016 next instruction.


but why it is not correct 2000-is one instruction and in 2004-next instruction?

as it is given address 2000 contain instruction i and address 2004 contain instruction i+1

So, should 2004 not contain next instruction?
Yes,there are different instructions at different addresses and each of 4 byte.

Branching is done at i+3 instruction with refrence to current pc or next instruction.

i----2000 to 2003

i+1----2004 to 2007

i+2----2008 to 2011

i+3---2012 to 2015----this is the branch instruction.

i+4---2016 to 2019




So on.



still confused ? Then Message me.
offset mtlbb??
+1 vote

Size of each instruction = 4 Bytes
Program counter Relative Addressing Mode
⇾ Assuming the first instruction starts at address zero

Offset should go from Address 16 to Address 0
⇒ Offset = 0 – 16 = (-16) ⇾ Final answer


Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,487 answers
95,294 users