Hi Siva,
If we implement method a)
Label address (or offset) depends on size of the branch
instruction.so I think, it is need to adjust each instruction offset
after selecting opcode of branch instruction(nested branches) in
second pass .
Correct - this is known as assembler relaxation.
I think linker relaxation also do the same thing but during the
linking process.
If both are same, Then which is better option?
Well, they are not exactly the same, since one takes place in the
assembler and one in the linker. There is no hard and fast rule to
say which option is better, and in fact some ports implement both.
Which you choose is really up to you. If you only have a branch
instruction to relax (and not a function call instruction) then it is
reasonable to assume that all branches will be to targets within the
same object file, and so you will probably find assembler based
relaxation easier to implement.
The advantages of assembler based relaxation are:
* Smaller object files. (When compared to linker based
relaxation, since for that you have to pass extra information
in the object files).
* Simpler to code.
The advantages of linker based relaxation are:
* It detects more opportunities for relaxation since it can
reduce the length of branches between locations in different
object files.
Cheers
Nick