in CO and Architecture edited by
14,483 views
54 votes
54 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 edited by
by
14.5k views

4 Comments

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.
0
0
ok.
0
0

PC store the Next Address of Instruction . 

Branch Instruction at : i+3 

PC → (i+3)+ 1 = i+4 .

Target Add = PC + Offset 

i = i + 4 + Offset 

-4 = offset . 

Given that Instruction is 4 B Long : (-4) * 4 = -16 

1
1

4 Answers

62 votes
62 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

3 Comments

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 ? 

3
3
what does cmp R1,R9,R10 DOES?
0
0

@sushmita

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

1
1
19 votes
19 votes
Ans:(-16)

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

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

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

$2008---r1,r9,r10$

$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

4 Comments

edited by
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.
1
1
offset mtlbb??
0
0

@shweta Mainly 2 types ke AM(Addressing Mode) hote hai 1)Sequential flow AM

2)Transfer of control AM-(i)PC Relative AM (ii)Base-Register AM 

Is question mai PC Relative AM ki baat chal rahi hai 

Coming to your question Relative Address or Offset or Displacement sab ek he hai bus diferent name hai.

0
0
4 votes
4 votes

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

1 vote
1 vote
EFFECTIVE ADDRESS = PC VALUE + ADDRESS FIELD VALUE(OFFSET)

2000= 2016 +OFFSET

OFFSET = -16
Answer:

Related questions