You are on page 1of 39

JEPPIAAR ENGINEERING COLLEGE

(A CHRISTIAN MINORITY INSTITUTION) JEPPIAAR EDUCATIONAL TRUST JEPPIAAR NAGAR RAJIV GANDHI ROAD CHENNAI 600 119

III YEAR B.TECH. - V SEM INFORMATION TECHNOLOGY This is a Certified Bonafide Record Work of ________________________________ Register No.__________________________ submitted for the Anna University Practical Examination held on _______________ in _________________________ Laboratory during the year 2010-2011.

Signature of the HOD

Signature of the Lab-In-Charge Examiners Internal: _________________ External: _________________

Date: ____________

Jeppiaar Engineering College


Rajiv Gandhi Salai, Chennai - 600119 (T. N.)

Department of Information Technology


Lab Record for the Academic Year 2010-11 (In accordance with Anna University syllabus)

SUBJECT SUBJECT CODE SEMESTER STREAM

: : : :

SYSTEM SOFTWARE LAB CS2308 B Tech V SEM Information Technology

LAB INSTRUCTOR (S) :

Lab Incharge

S.No 1 2 3 4 5 6 7

Contents Lab Objective Introduction About Lab Guidelines to Students Description about System Software Concepts List of Lab Exercises (Syllabus Programs (AU) ) Solutions for Programs References

Page No

Lab Objective

1. To understand the relationship between system software and machine architecture. 2. To know the design and implementation of assemblers 3. To know the design and implementation of linkers and loaders. 4. To have an understanding of macro processors. 5. To have an understanding of system software tools.

INTRODUCTION ABOUT LAB


There are 70 systems installed in this Lab. Their configurations are as follows : Processor RAM Hard Disk Mouse : Network Interface card Software 1. All systems are configured in DUAL BOOT mode i.e, Students can boot from Windows XP or Linux as per their lab requirement. i. This is very useful for students because they are familiar with different Operating Systems so that they can execute their programs in different programming environments. 2. Each student has a separate login for database access 3. Oracle 9i client version is installed in all systems. On the server, account for each student has been created. i. This is very useful because students can save their work ( scenarios, pl/sql programs, data related projects ,etc) in their own accounts. Each student work is safe and secure from other students. 4. Latest Technologies like DOT NET and J2EE are installed in some systems. Before submitting their final project, they can start doing mini project from 2nd year onwards. 5. i. projects. 6. Software installed: C, C++, JDK1.6, OFFICE-XP, J2EE and DOT NET, Rational Rose. 7. Systems are provided for students in the 1:1 ratio. 8. Systems are assigned numbers and same system is allotted for students when they do the lab. Rational Rose Software is installed in some systems Using this software, students can depict UML diagrams of their : : 2 GB : : 160 GB Present Optical Mouse Pentium 4 2.40 GHz

GUIDELINES TO STUDENTS:
1 Equipment in the lab for the use of student community. Students need to maintain a proper decorum in the computer lab. Students must use the equipment with care. Any damage is caused is punishable. Students are required to carry their observation / programs book with completed exercises while entering the lab.

Students are supposed to occupy the machines allotted to them and are not supposed to talk or make noise in the lab. The allocation is put up on the lab notice board.

Lab can be used in free time / lunch hours by the students who need to use the systems should take prior permission from the lab in-charge.

Lab records need to be submitted on or before date of submission.

Students are not supposed to use floppy disks, pendrives, CDs etc.

DESCRIPTION ABOUT SYSTEM SOFTWARE CONCEPTS SYMBOL TABLE


Data structures used in assembler algorithm: OPTAB and SYMTAB are the two [major internal] data structures used in assembler. OPTAB is a opcode table which contains two columns namely mnemonics operation code and their corresponding machine language equivalents. OPTAB is used to look up for opcodes to translate them to their machine code during pass2 phase of Two-pass Assembler. SYMTAB: Symbol table is a data structure used by a language translator such as a compiler or assembler, where each identifier in a program's source code is associated with information relating to its declaration or appearance in the source, such as its type, scope level and sometimes its location. SYMTAB is a symbol table used to store values(addresses) assigned to labels. During pass one of the assembler, labels and their assigned addresses, are entered into the SYMTAB as they are encountered in the source program. During pass2, symbols (used as operands ) are looked up in SYMTAB to obtain the addresses to be inserted in the assembled instructions. Input File (File name - srcpgm.txt): 1 0 LDA ZERO 2 0 LDX ZERO 3 RLOOP TD INPUT 4 0 JEQ RLOOP 5 ZERO WORD 0 6 INPUT BYTE X 'F1' Contents In Symbol Table Contents In Opcode Table

Symbol Names
RLOOP ZERO INPUT

Symbol Values
1006 100C 100F

Mnemonic Code
(ASL) LDA LDX TD JEQ

Opcode
(HD) 3A 3B 1A 4A

A symbol table contains information to locate and relocate symbolic definitions and references. It makes an entry in the symbol table for each symbol that is defined or referenced in the input file and is needed during linking. The symbol table is then used by the link editor during relocation.

A symbol table contains the following information:


name

name of symbol in input file. A value of zero indicates the symbol table entry has no name; otherwise, the value represents the symbol name.
value

Value of the associated symbol. This value is dependent on the context; for example, it may be an address, or it may be an absolute value. Uses: 1. During assembling (i.e during Source code to object code translation) 2. During Relocations, it is used by link editor. 3. During Linking of different object files - During the linking of different object files, a linker will use these symbol tables to resolve any unresolved references.

ASSEMBLER
Definition: The job of any assembler is to translate source program to object code. That is to convert from Assembly Language to machine language in terms of binary object code. Types of Assembler: Assembler Single Pass Pass 1 Two Pass Pass2

Single Pass Assembler: A one pass assembler passes over the source file exactly once, in the same pass collecting the labels, resolving future references and doing the actual assembly. The difficult part is to resolve future label references and assemble code in one pass.

Two Pass Assembler: A two pass assembler does two passes over the source file ( the second pass can be over a file generated in the first pass ). In the first pass all it does is looks for label definitions and introduces them in the symbol table. In the second pass, after the symbol table is complete, it does the actual assembly by translating the operations and so on.

Source Code

Assembler Pass Pass 1 2

Object Code

The simplest organization for an assembler is a two-pass organization. Assembly language control structures cannot be written without forward references. In order to handle forward reference, the program needs to be scanned twice. In other words a two pass assembler is needed. The memory address for a label cannot be assigned until its definition has been read, but code generation for jumps and branches requires knowing the address of the jump or branch target. Thus the assembler makes two passes through the input. During the first pass, the assembler assigs memory addresses to labels. During the second pass, Machine code is generated.

Two Pass Assembler Pass 1 (define symbols): 1. Assign addresses to all statements in the program. [Determines the length of machine instruction (from OPTAB) & calculate location counter (LOCCTR) value. ] 2. Save the addresses assigned to all labels for use in Pass 2 ( i.e Generate SYMTAB ) 3. Process some assembler directives (BYTE, RESW, etc.)

Pass 1 :

Source Code

Pass 1
Intermediate File SYMTAB SOURCE CODE Label
READ TD INPUT

Opcode
START LDX LDA RLOOP JEQ WORD BYTE END

Operand
1000 ZERO ZERO INPUT RLOOP X 'F1' 1000

Pass 1
INTERMEDIATE FILE SYMTAB

Address Label
1000 1000 1003 1006 1009 100C 100F READ TD INPUT

Opcode
START LDX LDA RLOOP JEQ WORD BYTE END

Operand
1000 ZERO ZERO INPUT RLOOP X 'F1' 1000

Symbol Name
1006 100c 100f

Symbol Value
(data / addr ) RLOOP ZERO INPUT

Pass 2 (assemble instructions and generate object program): 1. Look up address of symbols in SYMTAB, if needed. 2. Generate machine instructions (by referring OPTAB & SYMTAB) and Calculate location counter (LOCCTR) value. 3. Generate data values defined by BYTE, WORD 4. Processing of assembler directives not done during Pass 1 5. Write the object program and the assembly listing.

Pass 2 :

Intermediate File

SYMTAB

OPTAB

Pass 2
INTERMEDIATE FILE

Object Code

SYMTAB

OPTAB

1000 1000 1003 1006 1009 100C 100F

Address Label Opcode Mnemonic Object


START Code LDX LDA 3A LDA LDB 3B TD RLOOP TD 1A JEQ JEQ 4A WORD INPUT BYTE END READ Code

Operand
1000 ZERO ZERO INPUT RLOOP X 'F1' 1000

Symbol Symbol Name Value


1006 100c 100f RLOOP ZERO INPUT

Pass 2
OBJECT PROGRAM
H T E READ 1000 1000 1000 10 10 3A100c 3B100c 1A100f 4A1006

Appearance of Object Program : Header Record Col. 1 Col. 2-7 Col. 8-13 Col. 14-19 Col. 1 Col. 2-7 Col. 8-9 Col. 10-69 Col.1 Col.2-7 H Program name Starting address (hex) Length of object program in bytes (hex) Text Record T Starting address in this record (hex) Length of object code in this record in bytes (hex) Object code (69-10+1)/6=10 records End Record E Address of first executable instruction (hex). (END program_name)

Assembly of Instruction

Instruction
COMP ZERO

Opcode
COMP Referred in OPTAB
in Instruction as data

Operand
ZERO
in Register as Register name in Memory as address / symbol

OPTAB
Opcode (ASL)
STL JSUB LDA COMP JEQ J STA LDL RSUB

SYMTAB Object Code 28 1030


COPY FIRST CLOOP ENDFIL EOF THREE ZERO RETADR LENGTH BUFFER RDREC 1000 1000 1003 1015 1024 102D 1030 1033 1036 1039 2039

Object Code (HD)


14 48 00 28 30 3C 0C 08 4C

Forward Reference: Forward reference means; reference to an instruction which has not yet been encountered by the assembler. A forward reference occurs when a use of a label in an operand appears earlier in the code than its definition.
Loc 1000 1003 1006 Label FIRST CLOOP Opcode Operand Object Code STL JSUB LDA RETADR 141033 RDREC LENGTH 482039 0C1036

1009 100C 100F 1012 1015 1018 101B 101E 1021 1024 1027 102A 102D 1030 1033 1036 1039

ENDFIL

EOF THREE ZERO RETADR RESW LENGTH R BUFFER

COMP JEQ JSUB J LDA STA LDA STA JSUB LDL RSUB BYTE WORD WORD 1 ESW RESB

ZERO ENDFIL WRREC CLOOP EOF BUFFER THREE LENGTH WRREC RETADR 081033 CEOF 3 0 1 4096

281030 301015 482061 3C1003 00102A 0C1039 00102D 0C1036 482061

Macro & Macro Processor


Definition of Macro: Macro is an abbreviation for a portion of text or sequence of instructions. A Macro represents a commonly used, group of statements in the programming language (source code). If a sequence is repeated frequently, it is tedious to write it several times. It can be converted into a procedure and called when required. This strategy needs a procedure call instruction and a return instruction. Macros provide an easy and efficient solution to the problem. Progra m Without Macro MOV EAX, P MOV EBX, Q MOV Q, EAX MOV P, EBX MOV EAX, P MOV EBX, Q MOV Q, EAX Program Using Macro The four duplicate lines may be replaced by Macro named as SWAP. SWAP is an abbreviation for the four statements SWAP EAX, P MOV EBX, Q MOV Q, EAX MOV EBX ENDM SWAP SWAP P, MACRO MOV

MOV P, EBX

Any Macro has three divisions namely, 1. Macro Definition (Declaration of the macro, Code of the macro, Macro termination directive ) 2. Macro Invocation or Macro Call 3. Macro Expansion .

Macro Definition: A macro definition is a way to give a name to a piece of text. After a macro has been defined, the programmer can write the macro name instead of the piece program. It allows programmer to write shorthand version of program, making the programming task less tedious and less error-prone. THE BASIC parts of Macro Definition are : 1. A macro header containing - the name of the Macro , MACRO assembler directive (or pseudo instructions) followed by parameters 2. The text comprising the body of the macro. 3. MEND - A Pseudo instruction marking the end of the macro definition Syntax for Macro Definition: Macro name MACRO parameter list

MEND Example : RDBUFF MACRO . . . . MEND &INDEV, &BUFADR, &LENGTH

Macro Call or Macro Invocation: A macro in Greek means "big" or "far". Macro call pattern that specifies how a short string is mapped to a long sequence of instructions. During assembling, Macro Call is followed by macro Expansion. Parts of Macro Call

1. Name of the Macro 2. The arguments (if any) to be used in expanding macros Syntax : <macro name> < arg1, arg2, . .. arg_n if any> Example : RDBUFF F1, BUF, LEN or SWAP

Macro Expansion: In the source code, whenever the name of the macro appears (i.e macro call), it is replaced with macro body. This is called Macro Expansion which is done by macro processor. After macro processing, the expanded file is given as input to the assembler, thus producing the same machine language code. Macro Expansion occurs while assembling and not during execution. Once completed, the Macro Definitions are discarded by the assembler. Steps involved in macro expansion by Macro Processor are

Arguments from the macro invocation are substituted for the parameters in the macro prototype (according to their positions). Parameter : In the definition of macro Argument : In the macro invocation. Comment lines within the macro body will be deleted. Macro invocation statement itself has been included as a comment line. The label on the macro invocation statement has been retained as a label on the first statement generated in the macro expansion.

Macro Processor: Macro Processor replaces each macro instruction with corresponding group of instructions.

Source Code
(with macro)

Macro Processor

Expanded Code

Compiler or Assembler

obj

Functions of Macro Processor Recognize macro definitions Save the macro definition Recognize macro calls Expand macro calls Types of Macro Processor: Single Pass Two Pass Single pass Macro Processor Algorithm: every macro must be defined before it is called one-pass processor can alternate between macro definition and macro expansion

nested macro definitions may be allowed but nested calls are not Two pass Macro Processor Algorithm: Pass1: Recognize macro definitions Pass2: Recognize macro calls nested macro definitions are not allowed. 1. 2. 3. Data Structures used in Macro Processor NAMTAB DEFTAB ARGTAB

NAMTAB (Name Table) Stores macro names Serves as an index to DEFTAB Pointers to the beginning and the end of the macro definition (DEFTAB) DEFTAB (definition table) body Stores the macro definition including macro prototype and macro Comment lines are omitted. References to the macro instruction parameters are converted to a positional notation for efficiency in substituting arguments.

ARGTAB (Argument Table) Stores the arguments of macro invocation according to their positions in the argument list As the macro is expanded, arguments from ARGTAB are substituted for the corresponding parameters in the macro body. Difference between Macro Call and Subroutine call No Macro Call The statements of expansion are generated 1 each time the macro are invoked 2 Memory is wasted 3 Saves Time The body of macro is inserted into the 4 object program every place the call is made. 5 Call to macro is made during assembly 6 No need of Return statement in source code Subroutine ( or procedure) Call the statement in a subroutine appears only once Saves Memory space Takes time to transfer control and load the referred procedure The body of called program is not inserted into the object program of calling program. Instead the control is transferred from Calling program to called program. Call to procedure is made during program execution Needs Return instruction to go back to caller routine.

MACRO DEFINITION AND MACRO CALL ( input to Macro Processor ) COPY A1 FIRST ALPHA INCR ONE BETA START MACRO LDA SUB STA MEND CLEAR A1 RESW RESW WORD RESW END 1000 ALPHA ONE BETA A 1 1 1 1 FIRST

MACRO EXPANSION ( output of Macro Processor ) COPY FIRST .A1 ALPHA INCR ONE BETA START CLEAR MACRO LDA SUB STA RESW 1 RESW 1 WORD RESW 1 END 1000 A ALPHA ONE BETA 1 FIRST

. in macro expansion (dot) stands for comment line Lines from 3 to 5 are substituted for line no 8 (i.e for the macro call A1)

Loaders
Loader: Loader is a system program that loads object code from secondary storage to main memory and starts execution. . In addition to copying a program into main memory, the loader can also replace virtual addresses with physical addresses. Most loaders are transparent, i.e., you cannot directly execute them, but the operating system uses them when necessary. The loader is usually a part of operating system's kernel, is responsible for loading executable files into main memory, i.e. RAM preparing them for execution & executing them. Object files come in three forms: Relocatable object file, which contains binary code and data in a form that can be combined with other relocatable object files at compile time to create an executable object file. Executable object file, which contains binary code and data in a form that can be directly loaded into memory and executed. Shared object file, which is a special type of relocatable object file that can be loaded into memory and linked dynamically, either at load time or at run time.

Source Program

Assembler

Object Program

Loader

Object program ready for execution

Many Loaders do loading, relocation and linking. Some loaders doesnt support linking, so linker is used separately for linking and loader separately for loading & relocation. The loader performs the following functions. 1. Allocation : The loader determines and allocates the required memory space for the program Memory to execute properly. 2. Loading : copies programs from a storage device to main memory, where they can be executed. 3. Relocation : modifies the object programs, so that it can be loaded at an address different from the location originally specified 4. Linking : combines two or more separate object programs and supplies the information needed to allow references between them. Type of loaders assemble-and-go loader absolute loader (bootstrap loader) relocating loader (relative loader)

direct linking loader


Design options linkage editors dynamic linking bootstrap loaders

Assemble and go Loader: The assembler simply places the code into core, and the "loader" consists of one instruction that transfers to the starting instruction of the newly assembled program. A compile and go loader is one in which the assembler itself does the processes of compiling then place the assembled instruction in the designated memory locations. The assembly process is first executed and then the assembler causes a transfer to the first instruction of the program. One method of performing the loader functions is to have the assembler run in one part of memory and place the assembled machine instructions and data, as they are assembled, directly into their assigned memory locations (Figure). When the assembly is completed, the assembler causes a transfer to the starting instruction of the program. This is a simple solution, involving no extra procedures. It is used by the WATFOR FORTRAN compiler and several other language processors. Such a loading scheme is commonly called "compileand-go" or "assemble and-go." It is relatively easy to implement. The assembler simply places the code into core, and the "loader" consists of one instruction that transfers to the starting instruction of the newly assembled program. However, there are several apparent disadvantages. First, a portion of memory is wasted because the core occupied by the assembler is unavailable to the object program. Second, it is necessary to retranslate (assemble) the user's program deck every time it is run. Third, it is very difficult to handle multiple segments, especially if the source programs are in different languages (e.g., one subroutine in assembly language and another subroutine FORTRAN or PL/I). This last disadvantage makes it very difficult to produce orderly modular programs.

Characteristic: The object code is stored in memory after assembly Single JUMP instruction. Advantage: Simple and easier to implement. No additional routines are required to load the compiled code into the memory. Disadvantage: Whenever the assembly program is to be executed, it has to be assembled again There is a need to re-assemble the code every time it is to be run.

Programs have to be coded in the same language. It becomes increasingly difficult to handle large number of segments when the input code is written in a variety of HLL say one routine in pascal and one in FORTRAN and so on. Such loader make designing modular programs and systems near impossible.

ABSOLUTE LOADER:
An absolute loader is the simplest type of loader. Loads a program / process into a single fixed area of memory. It doesnt do program relocation and linking. All functions are accomplished in a single pass. When a computer is first turned on or restarted, a special type of absolute loader, called a bootstrap loader, is executed. The bootstrap loader, loads the first program to be run by the computer usually an operating system One some computers, an absolute loader program is permanently resident in a read-only memory ROM One some computers, theres a built-in hardware which read a fixedlength record from some device into memory at a fixed location. After the read operation, control is automatically transferred to the address in memory

Advantages of Absolute Loader: Simple, easy to design and implement. Since more core memory is available to the user there is no memory limit. Disadvantages of Absolute Loader: The programmer must specifically tell the assembler the address where the program is to be loaded. It is very difficult to relocate in case of multiple subroutine.

Programmer has to remember the address of each subroutine and use that absolute address explicitly in other subroutines to perform subroutine linkage.

RELOCATING LOADER : Loaders that allow for program relocation are called Relocating Loaders. A relocating loader can load a program anywhere in main memory. So it is also known as Relative Loader It is often desirable to have more than one program at time in time sharing memory. In a multitasking operating system, a program called a dispatcher juggles the processor's time among different tasks and calls the loader when a program associated with a task is not already in main storage. The object program is loaded into memory wherever there is room for it. The actual starting address of the object program is not known until load time If we knew in advance exactly which programs were to be executed, we could assign address when the programs were assembled so that they would fit together without overlap or wasted space. Most of the time , it is not practical. Because of this , it is desirable to load a program into memory wherever there is room for it. In such a situation the actual starting address of the program is not known until load time.

There are the parts of the program that should remain the same regardless of where the program is loaded. The assembler does not know the actual location where are those parts of the object program that need modification. An object program that contains the information necessary to perform this kind of modification is called relocatable program. Relocation, which modifies the object program so that it can be loaded at an address different from the location originally specified. Loaders that allow for program relocation are called relocating loaders are relocating loaders or relative loaders. Advantage: more efficient packing of memory. Efficient sharing of the machine with larger memory and when several independent programs are to be run together. Support the use of subroutine libraries efficiently

Disadvantage: no external subroutines or libraries Modification record col 1 col 2-7 address col 8-9 (halfbyte) col 10 col 11-17 name : : : : : M relocation length flag (+/-) segment

col 1 : T col 2-7 : starting address col 8-9 : length (byte) col 10-12 : relocation bits col 13-72 : object code

Text record col 1 col 2-7 col 8-9 col 10-12 col 13-72 : : : : : T starting address length (byte) relocation bits object code

Two methods for specifying relocation modification record (Fig. 3.4, 3.5) relocation bit (Fig. 3.6, 3.7) each instruction is associated with one relocation bit these relocation bits in a Text record is gathered into bit masks Relocation bit 0: no modification is necessary 1: modification is needed Twelve-bit mask is used in each Text record since each text record contains less than 12 words unused words are set to 0 any value that is to be modified during relocation must coincide with one of these 3-byte segments e.g. line 210 Object program with relocation by bit mask - FFC - all ten words are to be modified - E00 - first three records are to be modified H COPY 000000 00107A T 000000 1E FFC 140033 481039 000036 280030 300015 481061 ... T 00001E 15 E00 0C0036 481061 080044 4C0000 454F46 000003 T 001039 1E FFC 040030 000030 E0105D 30103F D8105D T 001057 1C 800 100036 4C0000 F1 001000 T 001061 19 FE0 040030 E01079 301064 508039 DC1079 2C0036 E 000000 Here the bit mask FFC (representing the bit string 111111111100). In the first text record specifies that all 10 words of object code are to be modified during relocation. Similarly bit mask E00 represents that the first 3 words are to be modified .

Fig 3.7 Object Program with relocation by bit mask

LINKER
Loader Loading + relocation (sometimes Linking too) Linker linking alone Linking Loader The linking loader performs the process of linking and relocation. A loader, combines the functions of a relocating loader with the ability to combine a number of program segments that have been independently compiled into an executable program. A linking loader (or just a linker) is used to combine the multiple object modules used when a program contains several separately compiled modules. Two of its primary tasks are to relocate the code and data in each object module (since the compiler does not know where in memory a module will be placed), and to resolve symbolic references from one module to another. For example, a main program may reference a square root function called sqrt, and that function may be defined in a separate source module. The linker will then minimally have to assign addresses to the code and data in each module, and put the address of the sqrt function in the appropriate location(s) in the main module's code.

Compare between linking loader and linkage editor S.no Linking Loader Linkage Editor 1. Linking and loading are done at a Linking is done before loading. same time.[linking is done at load time.] 2. Suitable when a program is Suitable when a program is to be reassembled for nearly every executed many times without execution. being reassembled. 3. Searches library and resolves Resolution of external references and external references every time the library searching are performed only program is executed. once. 4. No special use. Can also be used to build packages of subroutines or other control sections. 5. Less flexible More flexible. Dynamic Linking Loader Comparison Linkage editors perform linking operations before the program is loaded for execution Linking loaders perform linking operations at load time Dynamic linking (dynamic loading, load on call) perform linking at execution time Delayed Binding Avoid the necessity of loading the entire library for each execution, i.e. load the routines only when they are needed Allow several executing programs to share one copy of a subroutine or library (Dynamic Link Library, DLL) Direct Linking Loader : A loader which combines the functions of a relocating loader with the ability to combine a number of program segments that have been independently compiled into an executable program. The direct linking loader is the most common type of loader. This type of loader is a re-locatable loader. The loader can not have the direct access to the source code. And to place the object code in the memory there are two situations: either the address of the object code could be absolute which then can be directly placed at the specified location or the address can be relative. If at all the address is relative then it is the assembler who informs the loader about the relative addresses.

The assembler should give the following information to the loader 1. The length of the object code segment 2. The list of all the symbols which are not defined 111 the current segment but can be used in the current segment. 3. The list of all the symbols which are defined in the current segment but can be referred by the other segments. The list of symbols which are not defined in the current segment but can be used in the current segment are stored in a data structure called USE table. The USE table holds the information such as name of the symbol, address, address relativity. The list of symbols which are defined in the current segment and can be referred by the other segments are stored in a data structure called DEFINITION table. The definition table holds the information such as symbol, address. ESTAB (External Symbol Table) External External Symbol Symbol Name Address

Label REF1 LISTA REF2 LISTB+4

Expression

Program A Program B Program C LISTA, ENDA LISTB, ENDB LISTC, ENDC local, R, PC external local, A local, A external local, R local, A local, R external local, R, PC external external external external local, A local, R external external external local, R local, A local, A external external

REF3 ENDA-LISTA REF4 ENDA-LISTA+LISTC REF5 ENDC-LISTC-10 REF6 ENDC-LISTC+LISTA-1 REF7 ENDA-LISTA-(ENDB-LISTB) REF8 LISTB-LISTA

The intermediate file (or Load map or ESTAB) at the end of Pass1 of Direct Linking Loader is:

Control Section Name PROGA

Symbol name

Address

Length

LISTA ENDA PROGB LISTB ENDB PROGC LISTC ENDC A Bootstrap Loader: of itself, or to load ROM. An Absolute Loader: a program starting A Relocating Loader: same program A Linking Loader: and load them as a A Linkage Editor: load module that

1000 70 1040 0 1054 0 1046 88 10a6 0 10b6 0 109e 57 10ce 0 10e0 0 It uses its first few instructions to either load the rest another loader, into memory. It is typically stored in Can only load absolute object files, i.e., can only load from a certain, fixed location in memory. Can load relocatable object files and thus can load the starting at any location. Can link programs that were assembled separately, single module. Links programs and does some relocation. Produces a can be later loaded by a simple relocating loader.

Object Program Records Involved


Header Text Records Modification Records : : : control section length object code (for loading) relocation, linking operations

End

transfer address(es)

The main data structure needed for our linking loader is an external symbol table ESTAB. This table is used to store the name and addresses of each external symbol in the set of control sections being loaded. It also indicates , in which, control section, the symbol is defined.. It is implemented as hash table.

PROGADDR where the linked CSADDR of control section to all relative

Two important Variables: PROGgram load ADDRess. Beginning address in memory program is to be loaded. - Control Section ADDRess. It contains the starting address currently being scanned by the loader. This value is added

addresses within the control section to convert them to actual addresses. Pass 1 Assigns addresses to all external symbols. Define the staring address of each section and use a table to store the name and address of each defined symbol. Pass 2 Performs the actual loading, relocation, and linking

Actions
Load and relocate object code in text records. Link external symbols using ESTAB Determine transfer address and start execution. Detect undefined symbols

Memory

Source Program

Assembler

Object Program

Linker Executable Code Loader


Object program ready for execution

List of Lab Exercise:


Implement a symbol table with functions to create, insert, modify, search, and display. 1. 2. Implement pass one of a two pass assembler. Implement pass two of a two pass assembler.

Implement a single pass assembler. Implement a macro processor. 3. 4. 5. Implement an absolute loader. Implement a relocating loader. Implement pass one of a direct-linking loader.

6. 7.

Implement pass two of a direct-linking loader. Implement a simple text editor with features like insertion / deletion of a character, word, and sentence.

306082 05014

1. SYMBOL TABLE Aim: To create a symbol table and do operations such as search, modify, insert, display. Algorithm: 1. Start the program.

2. Get the source program (input) from the user and write it into a file. 3. Get first line from the file. 4. If opcode=START then do the following. (i) Save operand as starting address. (ii)Initialize locctr to starting address. 5. Otherwise initialize locctr to 0. 6. If there is a symbol in the Label field then do the following. (i) Search symtab for label. (ii)If found then set error flag otherwise insert (label,locctr) into symtab. 7. Search Optab for opcode. 8. If found, then add 3 to locctr. 9. If opcode=WORD, then add 3 to locctr. 10.If opcode=RESW then add 3* operand to locctr. 11.If opcode=RESB then add operand to locctr. 12.If opcode=BYTE then find length of constant in bytes and add it to locctr. 13.Repeat steps (6) to (12) until END (opcode) is reached. 14.Print 1. Modify 2. Search 3. Display 4. Insert . 15.Get choice from user. 16.If choice is 1 then do the following. (i) Get the existing and new symbol names from user. (ii) Search the symtab for the existing symbol name. (iii) If found, then replace it with new symbol name else display error. 17.If choice is 2 then do the following. (i) Get the symbol name to be searched from the user. (ii)Search the symtab for the symbol. (iii) If found, then display the symbol along with its address. (iv) Otherwise, display symbol not found. 18.If choice is 3 then print the symbols along with their addresses found in the symtab. 19.If choice is 4 then do the following. (i) Get the symbol name to be inserted along with its address. (ii)Enter these data into the symtab. 20.Stop.

306082 05014 2. TWO PASS ASSEMBLER PASS I

Aim: To implement the assembler algorithm Pass I.

Algorithm: 1. 2. 3. 4. Start the program. Get the input from user and store it in a file. Read first input line. If opcode=START then do the following. (i) Save operand as starting address. (ii) Initialize locctr to starting address. (iii) Write line to intermediate file. (iv) Read next input line. 5. Otherwise initialize locctr to 0. 6. If the input line is not a comment line then do steps 7 to 14. 7. If there is a symbol in the Label field then do the following. (i) Search symtab for label. (ii) If found then set error flag otherwise insert (label,locctr) into symtab. 8. Search Optab for opcode. 9. If found, then add 3 to locctr. 10.If opcode=WORD, then add 3 to locctr. 11.If opcode=RESW then add 3* operand to locctr. 12.If opcode=RESB then add operand to locctr. 13.If opcode=BYTE then find length of constant in bytes and add it to locctr. 14.If steps 9 to 13 are not satisfied, then set error flag. 15.Write line to intermediate file and read next input line. 16.Repeat steps 6 to 15 until END (opcode) is reached. 17.Write last line to intermediate file. 18.Save (locctr - starting address) as program length. 19.Stop.

3060820 5014

3. TWO PASS ASSEMBLER PASS II

Aim: To implement the assembler algorithm Pass II. Algorithm: 1. Start the program. 3. Read first input line from intermediate file. 4. If opcode=START, then write listing line and read next input line. 5. Write header record to object program. 6. Initialize first Text record. 7. If the input line is not a comment line then do the steps from 7 to 12. 8. Search Optab for opcode. 9. If found, then do step 9 else go to step 10. 10.If there is a symbol in Operand field then do the steps (i) to (iii) else store 0 as operand address. (i) Search symtab for operand. (ii) If found, then store symbol value as operand address. (iii) Otherwise, store 0 as operand address and set error flag. 11.If Opcode=BYTE or WORD then convert constant to object code. 12.If object code will not fit into the current text record then write text record to object program and initialize new text record. 13.Add object code to text record. 14.Read next input line. 15.Repeat steps (6) to (13) until END (opcode) is reached. 16.Write End record to object program. 17.Stop.

3060820 5014

4. SINGLE PASS ASSEMBLER Aim: To implement the single pass assembler algorithm. Algorithm: 1. Start the program. 2. Get the source program(input) from the user and write it into a file. 3. Read the first line from the file. 4. If opcode=START then do the following. (i) Save operand as starting address. (ii) Initialize locctr to starting address. 5. Otherwise initialize locctr to 0. 6. If there is a symbol in the Label field then do the following. (i) Search symtab for label. (ii)If found then set error flag otherwise insert (label,locctr) into symtab. (iii) Process table of incomplete instructions. 7. Search Optab for opcode. 8. If found, then add 3 to locctr. 9. If opcode=WORD, then add 3 to locctr. 10.If opcode=RESW then add 3* operand to locctr. 11.If opcode=RESB then add operand to locctr. 12.If opcode=BYTE then find length of constant in bytes and add it to locctr. 13.If there is a symbol in Operand field then do the steps (i) to (iii) else store 0 as operand address. (i) Search symtab for operand. (ii)If found, then store symbol value as operand address. (iii) Otherwise, enter symbol name and address of the instruction into the table of incomplete instructions.

14.If Opcode=BYTE or WORD then convert constant to object code. 15.Read next input line. 16.Repeat steps (6) to (15) until END (opcode) is reached. 17.Display the output (object program). 18.Stop.
3060820 5014

5. ABSOLUTE LOADER Aim: To implement the absolute loader algorithm. Algorithm: 1. Start the program. 2. Get the input program from the user. 3. Read header record. 4. Verify program name and length. 5. Read first text record. 6. Repeat steps (7) and (8) till record type is not E. 7. Display the object code along with its memory location at which it will be loaded. 8. Read next object program record. 9. Stop.

306082 05014

6. DIRECT LINKING LOADER PASS I Aim: To implement the Pass I algorithm of a direct linking loader. Algorithm: 1. 2. 3. 4. 5. 6. 7. Get program address. Set csaddr to progaddr. Repeat the following steps until end of input is reached. Read next input record. Set cslth to control section length. Search estab for control section name. If found then set error flag otherwise enter control section name into estab with value csaddr. 8. Do steps 8 to 11 until record type=E. 9. Read next input record. 10.If record type=D then do steps from 10 to 11 for every symbol in the record. 11.Search estab for symbol name. 12.If found then set error flag else enter symbol into estab with value csaddr+indicated address. 13.Add cslth to csaddr 14.Stop.

306082 05014

7. DIRECT LINKING LOADER PASS II Aim: To implement the Pass II algorithm of a direct linking loader. Algorithm: 1. 2. 3. 4. 5. 6. 7. 8. Set csaddr to progaddr. Set execaddr to progaddr. Repeat the following steps until end of input is reached. Read next input record. Set cslth to control section length. Repeat steps 7 to 12 until record type=E. Read next input record. If record type= T then move object code from record to location csaddr+specified address. 9. Otherwise if record type=M then do steps 10 to 12. 10.Search estab for modifying symbol name. 11.If found then add or subtract symbol value at location csaddr+specified address. 12.Otherwise set error flag. 13.If an address is specified in End record then set execaddr to csaddr+ specified address. 14.Add cslth to csaddr.

15.Display execution starts from execaddr. 16.Stop.

306082 05014

8. MACROPROCESSOR Aim: To implement the macroprocessor algorithm. Algorithm: 1. 2. 3. 4. 5. 6. Start the program. Get the input program to be processed. Repeat the following steps until end of the program is reached. Read the input line. If it is a macro definition i.e. opcode is MACRO then enter the macro name and definition into a file f1. Otherwise if it is a macro call, do the following steps. (i) Expand the macro i.e., get the definition from file (ii) Substitute arguments wherever used. (iii) Enter the definition into the expanded file. Otherwise if it is a simple statement, then enter the statement to the expanded file. Display the contents of the expanded file. Stop.

7. 8. 9.

3060820 5014

9. TEXT EDITOR AIM: To write a C program to count the no of various data types present in the given text. ALGORITHM: 1. Start 2. Declare the necessary variables and pointers. 3. Open the file f1. 4. Declare the vowels, consonants, digits, white space and other characters.

5. Declare the two functions scan line() and save file() with necessary arguments. 6. Using switch case as per the case, do the instructions that follow it. 7. Print the no. of vowels, consonants, no. of digits, no. of white spaces, no. of other characters and no. of lines. 8. Stop.

You might also like