Systems Programming Assemblers Part 4 Control Sections Prof. Dr. Hani Mahdi Department of Computer Science Al-Isra University, Amman, Jordan 1 1
Control Sections A Control Section is a part of the program that maintains its identity after assembly A Control Section is often used for subroutine or other logical subdivision of a program A Control Section can be assembled, loaded, and relocated independently May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 2 2
Program Linking Program Linking is used to link together logically related control sections Problem: The assembler does not know where any other control section will be located at execution time. When an instruction needs to refer to instructions or data located in another control section, the assembler is unable to process this reference. Solution The assembler has to generate information for such kind of references, called external references (References between control sections), that will allow the loader to perform the required linking. May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 3 3
Assembler Directives for Control Section START: start the first control section set program name as the control section name define the control section name as an external symbol CSECT: start a new control section specify the control section name define the control section name as an external symbol EXTDEF: External Definition EXTDEF name [, name] Define external symbols that may be used by other sections Control section names do not need to be named in an EXTDEF statement, they are automatically considered to be external symbols (In the following, these are COPY, RDREC, and WRREC ) EXTREF: External Reference EXTREF name [,name] Names symbols that are used in this control section and are defined elsewhere May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 4 4
Program with Multiple Control Sections Implicitly defined as an external symbol First control section: COPY Define external symbols External reference May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 5 5
Program with Multiple Control Sections Implicitly defined as an external symbol Second control section: RDREC External reference May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 6 6
Program with Multiple Control Sections Implicitly defined as an external symbol Third control section: WRREC External reference May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 7 7
How to Handle External References 15 0003 CLOOP +JSUB RDREC 4B100000 The operand RDREC is an external reference. The Problem The assembler has no idea where RDREC is The Solution The assembler inserts an address of zero The assembler can only use extended format (Format 4) to provide enough room for address (The relative addressing for external reference is invalid) The assembler must remember (via entries in SYMTAB) in which control section a symbol is defined The assembler passes information to the loader May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 8 8
How to Handle External References 190 0028 MAXLEN WORD BUFEND-BUFFER 000000 There are two external references in the expression, BUFEND and BUFFER. The assembler inserts a value of zero passes information to the loader Add to this data area the address of BUFEND Subtract from this data area the address of BUFFER On line 107, BUFEND and BUFFER are defined in the same control section and the expression can be calculated immediately. 107 1000 MAXLEN EQU BUFEND-BUFFER May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 9 9
Object Code with Multiple Control Sections May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 10 10
Object Code with Multiple Control Sections May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 11 11
Object Code with Multiple Control Sections May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 12 12
How Assembler to Handle Control Sections It processes each control section independently It establishes a separate LOCCTR (initialized to 0) for each control section It stores in SYMTAB the control section in which a symbol is defined It allows the same symbol to be used in different control sections It reports an error when attempting to refer to a symbol in another control section, unless the symbol is defined as an external reference References to unidentified external symbol are flagged as an error. It generates information in the object program for external references May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 13 13
New Records for External References Information about Defined external symbols named by EXTDEF Information about Referenced external symbols named by EXTREF May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 14 14
Revised Modification Record May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 15 15
Object Program COPY RDREC WRREC May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 16 16
Program Relocation As well as for program linking, the revised Modification record may still be used to perform program relocation. The same mechanism can be used for program relocation and for program linking. May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 17 17
Expressions in Multiple Control Sections Extended restriction Both terms in each pair of an expression must be within the same control section Legal: BUFEND-BUFFER Illegal: RDREC-COPY How to enforce this restriction When an expression involves external references, the assembler cannot determine whether or not the expression is legal. The assembler evaluates all of the terms it can, combines these to form an initial expression value, and generates Modification records. The loader checks the expression for errors and finishes the evaluation. May 2006 Systems Programming Assemblers - Hani Mahdi based on Beck s Book System Software Chapter 2 18 18