Clemson University -- CPSC 231 -- Fall 2009 Scope (visibility) scope in C is simple: normal declaration inside a procedure is visible only within that procedure normal declaration outside a procedure is visible to all code below that point in that source file external declaration (extern) informs the linker of a reference to a non- static/non-local variable or function in another source file scope in assembly is similar: unless otherwise specified, symbols are visible only within the source file (thus, you can't use "loop" as a label twice within the same source file, but each separate source file can use "loop" as a local label) for external references (i.e., between source files) a pseudo-op is used in one source file to indicate the global availability of a symbol defined in that file (i.e., exporting the symbol) and another pseudo-op is used in another source file to indicate use of that symbol (i.e., importing that symbol); up to the linker to match the uses with the definitions in MASM, the two pseudo-ops PUBLIC and EXTERN are used for these purposes in SPARC assembly, .global is used both in the exporting file and in the importing file using MASM-like pseudo ops: in C: define(EXTERN,global) define(PUBLIC,global) file a: .EXTERN sqrt file d: extern double sqrt(double); .EXTERN x /* can omit "extern" here; */ ... /* "static" means not public */ call sqrt extern int x; /* "referencing" */ ... ... /* declaration */ set x,%o0 int w; ld [%o0],%x_r ... set w,%o1 z = sqrt (y); st %x_r,[%o1] ... ... w = x; w: .word 0 ... file b: .PUBLIC sqrt file e: double sqrt(double argument){ sqrt: ... ... file c: .PUBLIC x file f: int x; /* "defining" decl. */ ... ... x: .word 0 ... note: C has static scoping; there are languages with dynamic scoping, such as APL and Perl, in which the variable names have to be resolved at run time based on the current call chain