.text .globl main main: jal pread # read first integer nop # move $s0,$v0 # save it in $s0 jal pread # read second integer nop # move $s1,$v0 # save it in $s1 jal pread # read third integer nop # move $s2,$v0 # save it in $s2 addu $s0,$s0,$s1 # compute the sum addu $s3,$s0,$s2 # result in $s3 li $v0,4 # print a heading la $a0,heading syscall move $a0,$s3 # move sum into parameter li $v0,1 # print the sum syscall li $v0,10 # exit syscall .data heading: .asciiz "The sum is: "
that modules (for us, subroutines) should not know about
each other's symbolic addresses.
It would violate the idea of modularity for
to do something to
But some symbolic addresses need to be used between modules.
pread is a symbolic address, and
main must know about it and use it in the
A symbol that a subroutine makes visible to other subroutines is
a global symbol.
Global symbols often label entry points.
Symbols that are not global are called local symbols.
A symbol is made global by
placing it in a list of symbols following the
Some languages use the word external for what we are
In the language C, a symbol that is visible to another module is called an external symbol. For example, the names of functions in C are external symbols.
Source programs for PC-SPIM (the older version of SPIM) are contained in a single file, which includes all subroutines. However, in professional software development each subroutine might be placed in a separate source file. Each file must say which of its symbolic addesses are global and might be referenced by other source files.
With QtSpim (the most recent version of SPIM) you can create separate source files and load them separately. For this example program:
pread.asm(see next page)
What global symbols are in the subroutine