JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
SPARC Assembly Language Reference Manual     Oracle Solaris 11.1 Information Library
search filter icon
search icon

Document Information

Preface

1.  SPARC Assembler Syntax

2.  Executable and Linking Format

3.  Directives and Pseudo-Operations

3.1 Assembler Directives

3.1.1 Section Control Directives

3.1.2 Symbol Attribute Directives

3.1.3 Assignment Directive

3.1.4 Data Generating Directives

3.2 Notation

3.3 Alphabetized Listing with Descriptions

3.4 Pseudo-Op Attributes

3.5 Pseudo-Op Examples

3.5.1 Example 1: Binding to C Variables

3.5.2 Example 2: Generating Ident Strings

3.5.3 Example 3: Data Alignment, Size, Scope, and Type

3.5.4 Example 4: "Hello World"

4.  Creating Data in Assembler

5.  SPARC Code Models

6.  Writing Functions -- The SPARC ABI

7.  Assembler Inline Functions and __asm Code

A.  Using the Assembler Command Line

B.  A Sample Assembler Program

C.  SPARC Instruction Sets and Mnemonics

Index

3.5 Pseudo-Op Examples

3.5.1 Example 1: Binding to C Variables

This example shows how to use the following pseudo-ops to specify the bindings of variables in C:

.common, .global, .local, .weak

The following C definitions/declarations:

    int foo1 = 1;
#pragma weak foo2 = foo1
    static int foo3;
    static int foo4 = 2;

can be translated into the following assembly code.

Example 3-1 Using Pseudo-ops to Specify C Variable Bindings

    .pushsection    ".data"

    .global   foo1    ! int foo1 = 1
    .align    4
foo1:
    .word  0x1
    .type  foo1,#object            ! foo1 is of type data object,
    .size  foo1,4                ! with size = 4 bytes
       
    .weak  foo2            ! #pragma weak foo2 = foo1
    foo2 = foo1

    .local  foo3            ! static int foo3
    .common  foo3,4,4

    .align  4            ! static int foo4 = 2
   foo4:
    .word  0x2
    .type  foo4,#object
    .size  foo4,4

    .popsection

3.5.2 Example 2: Generating Ident Strings

This example shows how to use the pseudo-op .ident to generate a string in the .comment section of the object file for identification purposes.

.ident            "myprog: This is an example of an ident string"

3.5.3 Example 3: Data Alignment, Size, Scope, and Type

The pseudo-ops shown in this example are .align, .global, .type, and .size.

The following C subroutine:

int sum(a, b)
    int a, b;
{
    return(a + b);
}

can be translated into the following assembly code:

    .section  ".text"

    .global  sum

    .align  4

sum:             
    retl
    add  %o0,%o1,%o0            ! (a + b) is done in the

                            ! delay slot of retl

    .type  sum,#function            ! sum is of type function
    .size  sum,.-sum            ! size of sum is the diff

                            ! of current location
                            ! counter and the initial
                            ! definition of sum      

3.5.4 Example 4: “Hello World”

The pseudo-ops shown in this example are .section, .ascii, and .align. The example calls the printf function to output the string "hello world".

    .section            ".data1"
    .align        4
.L16:
    .ascii   "hello world\n\0"

    .section  ".text"
    .global  main
main:
    save  %sp,-96,%sp
    set  .L16,%o0
    call  printf,1
    nop
    restore