How Branching works in low level?

·

1 min read

the for loop that you use in programming is basically a implementation of BRANCH instruction.In this blog we will discuss how this BRANCH instruction works.

In normal program execution,program is extracted from memory and and PC is incremented by 4 and when it encounters BRANCH or CALL instruction PC is incremented by that location value (in case of CALL instruction return address is stored).

By following steps branching works ->

1. MEMORY ADDRESS <- [PC]; READ MEMORY IR<-MEMORY READ PC = [PC] + 4 =>Here normal fetch and increment step occurs

2.Decode Instruction; RA<-[R5]; RB<-[R6]; =>Here instruction is decoded and intermediate registers are filled with values of register R5 & R6

3. COMPARE [R4] & [R5] IF [R4] == [R5] then increment PC = [PC] + OFFSET

=> Check the condition if it is true then branch else continue.

Then no actions needed after this ......