SPARC Segments



C Variables



SPARC segments



SPARC segments



SPARC memory organization

location description
0x0 1 page of system-related stuff
0x2000 text segment
data segment
bss segment
unused memory
%sp stack segment



text segment



data segment



Example: Hello World

main () { printf("hello world\n"); }
can be written as
include(macrodefs.m)
        .global printf
format: .asciz  "hello world\n"
        .align  4
        beginmain
        set     format, %o0
        call    printf
        nop
        endmain
String is in text segment, and is read-only.



.global

declarations



.align

declaration



Example: Array of Pointers

char * wkday [] = {"mon",
                   "tue", "wed", "thu",
                   "fri", "sat", "sun"}
get pointer to Thursday (wkday[3]) into %o0:
        .align  4
        .global wkday
wkday:  .word   monm, tuem, wedm
        .word   thum, frim, satm,
        .word   sunm
monm:  .asciz  "mon"
        ...
sunm:  .asciz  "sun"

set wkday + (3 << 2), %o0 ld [%o0], %o0



bss segment



bss segment examples

	.bss
	.align	4
arraym:.skip	8 * 100
cm:	.skip	1
	.align	4
im:	.skip	4
	.align	2
	.common	shared, 50