When the program is loaded into the memory how is the branch

When the program is loaded into the memory, how is the branch and jump address are calculated?

Hint: For example: In the instruction, you can have

beq R1, R3, Exit

When loading the program into the memory, the address Exit needs to be resolved. How is the address

of next instruction is determined.

Explain in detail for:

i. Conditional branch

ii. Unconditional branch

Solution

Branch Address Calculation: In MIPS branch instruction has only 16 bits offset to determinenext instruction. We need a registeradded to this 16 bit value to determine next instruction and this register is actually implied by architecture. It is pc register since PC gets updated (PC+4) during the fetch cycle so that it holds the address of the next instruction. We also limit the branch distance to -2^15 to +2^15-1 instruction from the branch instruction.

step by step ;

@ Sign extend the 16 bit offset value to preserve its value

@ Multiply resulting value with 4.

@ Now we have 32 bit address. Add this value to PC+4 and that is the banch address.

Jump address: For Jump MIPS has only 26 bits to determine Jump location. Jumps are relative to PC in MIPS. Like branch, immediate jump value need to be word aligned; therefor we need to multiply 26 bit address with 4.

step by step:

@ MULTIPLY 26 bit value with 4.

@ Concatenate first 4 bits of PC value to left of our jump address.

@ Resulting address is the Jump address.

i. Conditionalbranch: A programming instruction that directs the compter to another pare of the program based on the results of the compare. High level language statements such as IF THEN ELSE and CASE are used to express the compare and conditional branch.

Example: compare field1with field2 goto matchRoutine if equal

ii. Unconditional branch: The GOTO provides unconditional branching by transferring control to a specified line. If the specified stetemente is not a executable statment then the controlis transferred to the first executable statement following that line.

GOTO line id

Example:

  10 Names$=\"ramya\"

20 GOTO Print

30 INPUT \"NEW NAME?\";Nmae$

40 GOTO Compute

50 print: PRINT \"NAME IS:\"; Name$

60 GOTO 30

70 Compute : ! Continue Program

.

.

NOTE: A GOTO with line id is not recommended and doesn\'t wprk in theIDE instead of GOTO statement ON GOTO statement allows control to be transferred to one of a list of statements based on the value of a numeric expression.

ON numerric expression GOTO line id list

When the program is loaded into the memory, how is the branch and jump address are calculated? Hint: For example: In the instruction, you can have beq R1, R3, E
When the program is loaded into the memory, how is the branch and jump address are calculated? Hint: For example: In the instruction, you can have beq R1, R3, E

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site