0% found this document useful (0 votes)
16 views29 pages

Ss Mod1

The document explains the functions of loaders and linkers in program execution, detailing how loaders allocate memory, link programs, adjust addresses, and load object programs into memory. It also describes macros and assembly language, highlighting the role of assemblers in converting assembly language into machine code through imperative statements, declaration statements, and assembler directives. Additionally, it outlines the design and operation of single pass assemblers, including the handling of forward references and the overall assembly process in two passes.

Uploaded by

hawks3099
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
16 views29 pages

Ss Mod1

The document explains the functions of loaders and linkers in program execution, detailing how loaders allocate memory, link programs, adjust addresses, and load object programs into memory. It also describes macros and assembly language, highlighting the role of assemblers in converting assembly language into machine code through imperative statements, declaration statements, and assembler directives. Additionally, it outlines the design and operation of single pass assemblers, including the handling of forward references and the overall assembly process in two passes.

Uploaded by

hawks3099
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 29
Loader he loader 1s « program wideh accepts the cbject programs, places the object programs into memory, prepares these programs for execution by the computer and initiates the execution Loader must perform four functions: 1, Mlocusin:- Alooaia space ia memoey Se procpans 2. Udsking :- Unktng of he progracn with other progreane needed for ta emscosion Relocation :- Adjust al addrees dependent locations 1 correspond to the allocated space. 4. Loading :- Physically places the object program into memory for the purpose of execution. Linker > Linker is a program in a system which helps to ink an object modules of program into a single object fle » It performs the process of linking. > Linker are also called link editors. > Linking is process of collecting and maintaining plece of code and data into a single fle. > Linker also ink a particular module into system brary, >It takes object modules from assembler as input and forms an executable file as output for loader. > Linking is performed at both compile time, when the source code is translated into machine code and load time, when the program is loaded into memory by the loader. > Linking is performed at the last step in compiling a program, MACRO > Macro is a single line abbreviation of group of instructions. > K macro is a sequence of instructions, assigned by a name and could be used anywhere in the program. Assembly Language Statements > After machine level language, the next level of development in the evolution of computer languages was the Assembly Language. > Machine level language uses only the binary language. > But on the other hand, assembly language uses mnemonics or symbolic instructions in place of a sequence of 0s and Is. » As example, we can consider that, to add register A and B in a particular computer, assembly language uses the mnemonic ‘ADD B" >The programs written in the assembly language cannot be directly executed by the CPU because they are not written in the binary form, b > As a result some mechanism is needed to convert the assembly language into machine understandable form. > Asoftware program called assembler is used to accomplish this purpose. ‘Kn assembly program contains three kinds of statements: 1. Imperative statements 2, Declaration statements 3. Assembler directives 1. Imperative statements Itindicates an action to be performed during the execution of the assembled program, Each imperative statement typically translates into one machine instruction. eg MOV AB ADD B MULT A,B 2. Declaration statements- The syntax of declaration statements is: [Label] DS [label] DC The DS (short for declare storage)statement reserves areas of memory and associates names with them, eg. ADSI The above statement reserves a memory area of I word and associates the name A with it. The DC (short for declare constant) statement declare memory words containing constants eg. ONE DC‘ Associates the name ONE with a memory word containing the value'1’. 3. Assembler directives Assembler directives instruct the assembler to perform certain actions during the assembly of a program, Examples of assembler directives are: 1, START: specify name & starting address 2. END :end of source program to be assembled 3. ORIGIN < address spec> : indicate origin address 4, EQU :ithas the syntax EQU
5. LTORG : It specify where literals should be placed Rai dae Ce ge un ee ee Ey oe ern ue tara a equivalent (object code) along with the information for the loader. oe Executable co) oa Fig. : Role of Assemblers REENCAST (@) MATIC An assembler does the following: fof eRe Met adele NOC ner ed ON oe eon rt kus equivalent machine addresses CaSO es on aa en ee SCREENCAST 6) MANIC Types of assembler: STG ig Seu is ol SCREENCAST) MANIC Single pass assembler A single pass assembler scans the program only once and creates Cetera as Sees ae cr gu ean Cun Denne uu Screencast (@) manic Single Pass Assemblers Single pass assemblers are used when De ee ne ee au ead FES a a ce eed Cee cn Main problem ue pe Pee end SCREENCAST @) MANIC Forward reference problem OTe Taru re Sanu Ty defined somewhere in the program. But in some cases a symbol may be used prior to its definition. RM eus ec cucs DS Ru ou Ru Re aU ee) Pee etc ec ae inta; ty ct SCREENCAST) MANIC Yale WS 0 PRD ns ote PRE eC od 2. insert the symbol into SYMTAB, and mark this symbol undefined 3. the address that refers to the undefined symbol is added to a list of eee hus koe aad 4, when the definition for a symbol is encountered, the proper address for the symbol is then inserted into any instructions previous generated according to the forward reference list SCREENCAST 6) MAnIC Solutions for one pass assembler BM eee rE Eliminating forward references: Either all labels used in forward references are defined in the source program before they are referenced, or forward references to data items are prohibited. Le rate a Reset esa au nO ee ee) Cea Eat aee SCREENCAST 6) ManIC Design of an assembler h converts an assembly language * Assembler is system software w alent object code program to its equi * The input to the assembler is a source code written in assembly ng mnemonics) and the output is an object code. language (us * Basic Assembler function * Translating mnemonic language to i es to symbolic labels. s equivalent object code. * Assigning machine addre Assembly Machine language end other — —> irtormetion for the toader General design procedure Design of an assembler consist of the following steps: 1. Specify the problem 2. Specify the data structure 3. Define the format of data structure 4. Specify the algorithm 8. Look for modularity 6. Repeat steps 1 to § on modules y w Specity the problem (Statement of the problem) The tasks performed by the assembler can be grouped into 2 passes. Pass 1 Purpose: Define symbols and literals Determine length of each instruction Keep track of LC Remember values of symbols until pass2 Process some pseudo-ops Remember literals Pass. 2 Purpose : Generate object program > Look up values of symbols > Generate instructions > Generate data > Process pseudo-ops 2. Specify the data structure(Data bases) Pass 1 data bases 1. Input source program 2. Location Counter (LC) is used to keep track of each instruction’s location 3. A table, Machine Operation Table (MOT) that indicates the symbolic mnemonic for each instruction and its length 4. A table, Pseudo operation Table (POT) that indicates the symbolic mnemonic for each pseudo-ops 5. Atable , Symbol Table (ST),that is used to store each label and its corresponding value. 6. Atable , literal Table ( LT ),that is used to store each literal and its corresponding assigned location. 1. Acopy of the input to be used by pa 1. Copy of source program input to pass] 2, RLocation Counter (LC) is used to keep track of each instruction’s location 3. table, Machine Operation Table (MOT) that indicates the symbolic mnemonic for each instruction, its length binary machine opcode and format 4. Ktable, Pseudo operation Table (POT) that indicates the symbolic mnemonic for each pseudo-ops 5. Atable , Symbol Table ( ST ) prepared by passl,that is used to store each label and its corresponding value. 6, Ktable , Base Table (BT )that indicates which register is used as base register by USING pseudo-op 1. workspace INST is used to hold each instruction and its various parts. 8. workspace PRINTLINE is used to produce printed listing 9. workspace PUNCHCARD is used for converting assembled instructions to output needed by the loader 10. Outputin machine code tobe needed by the loader 3. Specify the format of Data structure (Data bases) Symbol ‘Boyte) (character) "JOHNDOOO” “FOUROCOO” “FIVEDDDD” “TEMPODO” FIGURE3B Symbol Title (6) for ps and pos? Designated relative address ‘Contents of base register (byte (Sbytes = Zante addres) cenoractod hexadecimal 1 me = a ou ae oO = 16 = 350006) Coser Availability Y ~ register specified In USING Prewdo-on IN ~ register never specified in USING Banuso op aubenauently made FIGURE 3.9. Base Table (BT) for pase 2 entries 4. Specify the algorithm PASS 1: DEFINE SYMBOLS & Literals ‘The purpose of the first pass is to assign a location to each instruction and data- defining pseudo-instruction, and thus to define values for symbols appearing in the label fields of the source program. Initially, the Location Counter (LC) is set to the first location in the program (relative address 0). Then a source statement is read. The operation-code field is examined to determine if it is a pseudo-op; if it is not, the table of machine op-codes (MOT) is searched to find a match for the source statement’s op-code field. The matched MOT entry specifies the ength (2,4 or 6 bytes) of the instruction. The operand field is scanned for the presence of a literal. If a new literal is found, it is entered into the Literal Table (L1) for later processing. The label field of the source statement is then ex- amined for the presence of a symbol. If there is a label, the symbol is saved in the Symbol Table (ST) along with the current value of the location counter. Finally, the current value of the location counter is incremented by the length of the instruction and a copy of the source card is saved for use by pass 2. The above sequence is then repeated for the next instruction. Pass2 :Generate code A card is read from the source file left by pass 1. As in pass 1, the operation code field is examined to determine if it is a pseudo-op; if it is not, the table of machine op-codes (MOT) is searched to find a match for the card’s op-code field. The matching MOT entry specifies the length, binary op-code, and the format- type of the instruction. The operand fields of the different instruction format types require somewhat different processing. After the instruction has been assembled, it is put into the necessary format for later processing by the loader. Typically, several instructions are placed on a single card (see Chapter 5 for a more detailed discussion). A listing line contain- ing a copy of the source card, its assigned storage location, and its hexadecimal representation is then printed. Finally, the location counter is incremented and Processing is continued with the next card. ‘The END pscudo-op indicates the end of the source program and terminates the assembly.

You might also like