SPARC Assembly Language Reference Manual

Exit Print View

Updated: July 2014
 
 

4.1 Examples

Here are some examples of writing declarations and definitions for various kinds of data types.

Example 4-1  Examples

The following demonstrates the use of the .word, .half, .byte, .xword, nword, and .asciiz pseudo-ops, along with .align, .skip, .global, and .local, to define data in .data, .rodata, and .bss sections.

! --------.data-----------------
        ! the .data section is used for normal read/write data
        .section        ".data"

        ! iii is a global integer (word), "iii"
        .global iii
        .align  4
iii:
        .word   12345678


        ! sss is a global short (half)
        .global sss
        .align  2
sss:
        .half   12345


        ! ccc is a static (local) char (byte)
        .local  ccc
        .align  1
ccc:
        .byte   12


        ! lll is a a global long long (xword)
        .global lll
        .align  8
lll:
        .xword  1234567812345678


        ! aaa is a global char string 
        .global aaa
        .align  1
aaa:
        .asciiz "a string"


        ! sss is a global pointer to a string (absolute addressing)
        .global sss
        .align  8
sss:
        .nword  aaa


        ! --------.rodata-------------------
        ! the .rodata section is used for read-only data
        .section        ".rodata"

        ! jjj is a global read-only integer (word)
        .global jjj
        .align  4
jjj:
        .word   12345678


        ! ---------.bss---------------------
        ! the .bss section is used for data allocated (as zeroes) at run-time
        ! data in this section does not occupy space in the ELF file
        .section        ".bss"

        ! kkk is a global "bss" integer allocated at run-time 
        .global kkk
        .align  4
kkk:
        .skip   4