SPARC Assembly Language Reference Manual

Exit Print View

Updated: July 2014
 
 

5.2.4 64–Bit with 13–Bit PIC

The 64-bit with 13-bit PIC code for add() might look like the following:

add:
.L900000106:
         rd      %pc,%o3
         sethi   %pc22(_GLOBAL_OFFSET_TABLE_-(.L900000106-.)),%g1
         add     %g1,%pc10(_GLOBAL_OFFSET_TABLE_-(.L900000106-.)),%g1
         add     %g1,%o3,%o3
         ldx     [%o3+%got13(sum)],%o1
         ld      [%o1],%o2
         add     %o2,%o0,%g5
         retl    ! Result =
         st      %g5,[%o1]

The address of sum is formed in two parts. The first four instructions form the address of the global offset table (GOT). Then a 13-bit offset into the GOT is used to load the address of sum. The dynamic linker puts the correct address for sum into the GOT at run-time.

The operators act as follows:

%pc22(...)R_SPARC_PC22 relocation
%pc13(...)R_SPARC_PC13
%got13(sum)R_SPARC_GOT13

The 32-bit with 13-bit PIC code for add() is similar to the above 64–bit with 13–bit PIC, but the ldx used for 64-bit code is changed to ld for 32-bit code.