150 likes | 332 Views
COP 3402 Systems Programming. Dr. Ali Orooji School of EECS University of Central Florida. Section 2.3.2. Symbol-Defining Statements symbol EQU value assembler puts the symbol and value in symbol table 1000 L1 EQU 500 L2
E N D
COP 3402 Systems Programming Dr. Ali Orooji School of EECSUniversity of Central Florida
Section 2.3.2 • Symbol-Defining Statements • symbol EQU value • assembler puts the symbol and value in symbol table • 1000L1 EQU 500 • L2 • * • L2-L3
Section 2.3.3 • Expressions • assemblers generally allow +, -, *, / • Absolute expression • either only absolute terms • or if relative terms, they occur in pairs with • opposite signs • relative terms may not enter into a multiplication or division • operation • Relative expression • relative terms occur in pairs as above; one extra • relative term (positive sign)
Block 1 Block 1 Block 2 Block 2 Section 2.3.4 • Program Blocks • segments of code that are logically rearranged within a single object program unit
Pass 1 • - a separate location counter for each block • - when storing a label in symbol table, store the • block number as well • At the end of pass 1, the length of each block is known; • the assembler can now assign a starting address to each • block Pass 2 the value for a label is the value in the symbol table plus the starting address for the block
0000 . . . Block 1 Block 1 0300 . . . 0150 . . . Block 2 Block 2 0450 . . . • Note that the assembler does not physically rearrange the generated code in the object program (the assembler puts the load address with object code; loader will load accordingly)
Section 2.3.5 Control Sections - segments that are translated into independent object program units CSECT 1 CSECT 2 - need to link together different control sections . assembler cannot do the linking . assembler provides information for each external reference that will allow the loader to perform the required linking - need extended format (type 4) for instructions containing external references
15 0003 CLOOP +JSUB RDREC 4B 1 00000 ni=11 e = 1 bp=00 no relative addressing 160 0017 +STCH BUFFER,X 57 9 00000 ni=11 x = 1 e= 1 bp=01 190 0028 MAXLEN WORD BUFEND-BUFFER 000000
main routine ------------------ shared tables and routines root segment Pass 1 tables and routines Pass1 segment Pass 2 tables and routines Pass2 segment ... ... ... ... ... Two-Pass Assembler with Overlay Structure main segment : 20K Pass 1 segment : 50K Pass 2 segment : 60K
Section 2.4.1 One-Pass Assemblers Why did we need two passes? forward references - data items - labels Load-and-go one-pass assemblers generate object code in memory for immediate execution (no object program is written out, and no loader is needed)
symtbl name value ref ptr RDREC 1000 101D . . . 1000 J RDREC . . 101D J RDREC . . 2000 RDREC ...
If the one-pass assembler generates object program • on secondary storage, i.e., not load-and-go assembler • - put zero when address not known (and remember the references using symtbl as before) • - when address is known, generate records to fill references • 1000 J RDREC 1000 J 0000 • . • . • 101D J RDREC 101D J 0000 • . • . • 2000 RDREC • 1000 2000 • 101D 2000
Section 2.4.2 • Multi-Pass Assemblers • in the two-pass assembler • symbol defining directives • MAXLEN EQU BUFEND-BUFFER • symbols on the right hand side must be • defined previously • A EQU B • B EQU C • C EQU
symtbl # of undef sym name value expression ref ptr HALFSZ MAXLEN HALFSZ HALFSZ EQU MAXLEN/2
MAXLEN EQU BUFEND-BUFFER symtbl # of undef sym ref ptr name value expression HALFSZ 1 MAXLEN / 2 MAXLEN 2 BUFEND-BUFFER HALFSZ BUFEND MAXLEN BUFFER MAXLEN PREVBT EQU BUFFER-1