Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why "bcl 20, 31, $+4" instructoin for obtaining the address of next instruction in LR? why not "bl $+4" or "bcl 20, xx, $+4"?

Tags:

powerpc

I have read the last Power ISA manual from IBM (https://openpowerfoundation.org/?resource_lib=power-isa-version-3-0) and says [in page 35; 2.4 Branch Instructions]:

Obtaining the address of the next instruction:Use the following form of Branch and Link.

bcl 20, 31, $+4

where this standard comes from? It appears in all manual of powerpc instruction set, but there is some reason for write that?

In fact, the GNU compiler use that instruction.

like image 374
Bosco Avatar asked Oct 30 '25 02:10

Bosco


1 Answers

Because on Power the instruction pointer isn't a general register we use this trick to get it into the LR.

$+4 is the next instruction which we jump to.

20 - corresponds in binary to 10100 which in Figure 40 means branch always.

31 is a condition register - which is ignored because of branch always.

So with this instruction we end up at the next instruction, and as a side effect we have LR containing the instruction address (of the instruction after the branch).

LR is effectively a return address (p.37 the if LK then LR <- CIA + 4 text) of the "subroutine" we just called (and don't need to return from. In Power this is used as a quick form compared to the stack).

like image 86
danblack Avatar answered Nov 02 '25 23:11

danblack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!