Reference Guide
138 Chapter 7
Programming Examples
5. Output of the cc -S Command
5. Output of the cc -S Command
This example shows how a simple C program generates assembly
language code. The program calls the printf() routine. To run the
assembled code, you need to link the file /usr/ccs/lib/crt0.o and
the C library file. Remember that the ld command requires that you link
the crt0.o file first in 32-bit mode only. You do not need to link
/usr/ccs/lib/crt0.o in 64-bit mode..
C Program Listing
main ()
{
printf ("Hello World\n");
}
Assembly Program Listing From the C
Compiler
.LEVEL 1.0
.SPACE $TEXT$,SORT=8
.SUBSPA $CODE$,QUAD=0,ALIGN=4,ACCESS=44,CODE_ONLY,SORT=24
main
.PROC
.CALLINFO CALLER,FRAME=0,SAVE_RP
.ENTRY
STW %r2,-20(0,%r30) ;offset 0x0
LDO 48(%r30),%r30 ;offset 0x4
ADDIL LR’$THIS_DATA$-$global$,%r27 ;offset 0x8
.CALL ARGW0=GR ;in=26;
BL printf,%r2 ;offset 0xc
LDO RR’$THIS_DATA$-$global$(%r1),%r26 ;offset 0x10
L$exit1
LDW -68(0,%r30),%r2 ;offset 0x14
BV %r0(%r2) ;offset 0x18
.EXIT
LDO -48(%r30),%r30 ;offset 0x1c
.PROCEND ;
.SPACE $TEXT$
.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44,SORT=16
.SUBSPA $CODE$
.SPACE $PRIVATE$,SORT=16
.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=16
$THIS_DATA$
.ALIGN 4
.STRINGZ “Hello World\n”
.SUBSPA $SHORTDATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=24