You are on page 1of 83

KALASALINGAM UNIVERSITY

[Kalasalingam Academy of Research and Education]


Anand Nagar, Krishnankoil - 626126

Department of Computer Science and Engineering

LAB MANUAL

CSE282 - System Software Lab

Course Coordinator Module Coordinator

(Dr.R.Murugeswari) (Dr.R.Ramalakshmi)

Programme Coordinator HOD/CSE


(Dr.K.Kartheeban) (Dr.R.Ramalakshmi)

1
UNIVERSITY
VISION

To be a Center of Excellence of International Repute in Education and Research.

MISSION

To Produce Technically Competent, Socially Committed Technocrats and Administrators


through Quality Education and Research.

DEPARTMENT
VISION

To become a Centre of Excellence in Teaching and Research in the field of Computer Science and
Engineering.

MISSION

To prepare the students for a prospective career in IT industry and for higher learning by
imparting sound technical knowledge.

To carry out research in cutting edge technologies in computer engineering to meet the
requirement of the industry and society.

2
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
CSE282 - SYSTEM SOFTWARE LAB

INDEX

Ex. No Experiments Page No

1. Symbol Table Manipulation 11

2. Pass One of a Two Pass Assembler 19

3. Pass Two of a Two Pass Assembler 28

4. Implementation of Single Pass Assembler 37

5. Implementation of Two Pass Macro 44

6. Implementation of Single Pass Macro 50

7. Implementation of Absolute Loader 57

8. Implementation of Relocation Loader 64

9. Implementation of Pass One Of Linking Loader 70

10. Implementation of Pass Two Of Linking Loader 75

11. Implementation of Text Editor 79

3
Introduction

 System software
 Acts as an intermediary between users and hardware
 Creates a virtual environment for the user that hides the actual computer
architecture
 Virtual machine (or virtual environment)
 Set of services and resources created by the system software and seen by
the user

The Role of System Software

Types of System Software

 System software is a collection of many different programs


 Operating system
 Controls the overall operation of the computer
 Communicates with the user
 Determines what the user wants

4
 Activates system programs, applications packages, or user programs to
carry out user requests

 User interface
 Graphical user interface (GUI) provides graphical control of the
capabilities and services of the computer
 Language services
 Assemblers, compilers, and interpreters
 Allow you to write programs in a high-level, user-oriented
language, and then execute them
 Memory managers
 Allocate and retrieve memory space
 Information managers
 Handle the organization, storage, and retrieval of information on mass storage
devices
 I/O systems
 Allow the use of different types of input and output devices

5
KALASALINGAM UNIVERSITY
(KALASALINGAM ACADEMY OF RESEARCH AND EDUCATION)
ANAND NAGAR, KRISHNAN KOIL – 626 126

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


EVEV SEMESTER 2016-2017

Laboratory Course Plan

Subject with code System Software Lab /CSE282


Course B.Tech (CSE)
Semester / Sec IV / A-D & SHIP
Course Credit 2
Course Coordinator Dr. R. Murugeswari
Module Coordinator Dr. R. Ramalakshmi
Programme Coordinator Dr. K.Kartheeban

Pre-requisite:

General understanding of operating system concepts and some programming


experience in C language.

 CSE284 – Operating Systems Lab

 CSE181 – Programming Languages Lab

Course Description:

This course provides an introduction to the topics include comparative machine


organizations, the design of assemblers and loaders, an introduction to operating
systems and an introduction to compiler design.
Course Objective:

1. To design and develop system software programs and tools.

PROGRAMME SPECIFIC OBJECTIVES (PSO)

A graduate of the Computer Science and Engineering Program will have

6
1. PSO1: Problem-Solving Skills: The ability to apply mathematics, science and
computer engineering knowledge to analyze, design and develop cost effective
computing solutions for complex problems with environmental considerations.
2. PSO2: Professional Skills: The ability to apply modern tools and strategies in
software project development using modern programming environments to
deliver a quality product for business accomplishment.
3. PSO 3 : Communication and Team Skill : The ability to exhibit proficiency in
oral and written communication as individual or as part of a team to work
effectively with professional behaviors and ethics.
4. PSO 4 : Successful Career and Entrepreneurship : The ability to create a
inventive career path by applying innovative project management techniques to
become a successful software professional, an entrepreneur or zest for higher
studies

PROGRAMME OUTCOMES

PO Description
1 Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the solution
of complex engineering problems.
2 Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
3 Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified
needs with appropriate consideration for the public health and safety, and the
cultural, societal, and environmental considerations.
4 Conduct investigations of complex problems: Use research-based
knowledge and research methods including design of experiments, analysis
and interpretation of data, and synthesis of the information to provide valid
conclusions.
5 Modern tool usage: Create, select, and apply appropriate techniques,

7
resources, and modern engineering and IT tools including prediction and
modeling to complex engineering activities with an understanding of the
limitations.
6 The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to the professional engineering practice.
7 Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and
demonstrate the knowledge of, and need for sustainable development.
8 Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
9 Individual and team work: Function effectively as an individual, and as a
member or leader in diverse teams, and in multidisciplinary settings.
10 Communication: Communicate effectively on complex engineering activities
with the engineering community and with society at large, such as, being able
to comprehend and write effective reports and design documentation, make
effective presentations, and give and receive clear instructions.
11 Project management and finance: Demonstrate knowledge and
understanding of the
12 Engineering and management principles and apply these to one’s own work,
as a member and leader in a team, to manage projects and in
multidisciplinary environments.
13 Life -long learning: Recognize the need for, and have the preparation and
ability to engage in independent and life -long learning in the broadest
context of technological change.

Course Outcomes:

CO1. Write efficient algorithms with good space and time complexity to simulate
functions of system softwares.
CO2. Design and develop code to demonstrate various system softwares like
assembler, loader, macro-processor and text editors.

8
CO3. Work effectively as an individual and communicate effectively with technical
community.

CO and PO Mapping

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO PSO PSO
1 2 3
CO1 S M M M
CO2 S S S S S S M
CO3 S S

S- Strong Correlation M- Medium Correlation L – Low Correlation

List of experiments (as per syllabus):


Cumula
Experi
No. of tive No.
ment
Name of the Experiment periods of
No.
periods
Cycle – I
Implement a symbol table with functions to create,
1. 3 3
insert, modify, search, and display.
2. Implement pass one of a two pass assembler. 3 6
3. Implement pass two of a two pass assembler. 6 12
4. Implement a single pass assembler. 3 15
5. Implement a macro processor. 6 21
Cycle – II
6. Implement an absolute loader. 3 24
7. Implement a relocating loader. 3 27
8. Implement pass one of a direct-linking loader. 3 30
9. Implement pass two of a direct-linking loader. 3 33
Implement a simple text editor with features like
10. 3 36
insertion / deletion of a character, word, sentence.

Projects:
1. Design and Implement a simple compiler
2. Develop a simple application using DBMS.

9
3. Develop a debugging system for your own language.

New Additional Experiments:


1. Design and implement a multi-pass assembler.
2. Design and implement symbol table with literals.
Assessment Method:

S.no Assessment Split up


Internal Assessment Regular Lab Exercises (10) (CO1)
1
(50 marks) Model Lab (30) (CO2)
Presentation of any one exercise (10) (CO3)
Algorithm (10) (CO1)
External Assessment
2 End Semester Program and Output (30) (CO2)
(50 marks)
Viva Voce (10) (CO3)

Evaluation Procedure for Internal and External Assessment:

Module Rubrics for assessment Marks (100)


 Poor : 0 - 5 (Not able to understand what is given and what
is expected)
 Normal : 5 - 10 ( Understood what is given but can't decide
Efficiency what is expected))
of  Good : 10 - 15 (Understood what is given and Understood 20
Algorithm the stated expectation)
 Very Good : 15 - 20 ( Understood what is given and
understood the stated expectation as well as the hidden
expectation)
 Extraordinary : 35-40 Marks (With good time and space
Efficiency complexity)
of  Used efficient algorithms : 25 - 35 40
program  Met problem requirements : 15 - 25
 Poor Logic : 0 - 15 Marks
 Aesthetic Output : 15 - 20
Output  User interactive input and output : 5 - 15 20
 No proper user interactive I/O operation : 0 - 5
Viva  Answered for more than 80 % Qs : 16 - 20 Marks 20

10
 50% - 80% - 11 - 15 Marks
questions  25% - 50 % - 6- 10 Marks
 0%-25% - 0 - 5 Marks

Ex. No : 1
SYMBOL TABLE CREATION
Date :

Aim:

To write a C program to implement a symbol table

Theory

Symbol table is a data structure to store the details about the symbols present in the
source program. It is created during pass 1 and will be used during pass 2. This table
stores the informations like symbol name, data type and address. The possible
operations on symbol table are insert, search and remove. The following built-in
functions of C can be used for implementation.

fscanf()

Description
The C library function int fscanf(FILE *stream, const char *format, ...) reads
formatted input from a stream.
Declaration
Following is the declaration for fscanf() function.

11
int fscanf(FILE *stream, const char *format, …)

Parameters

 stream -- This is the pointer to a FILE object that identifies the stream.
 format -- This is the C string that contains one or more of the following
items: Whitespace character, Non-whitespace character and Format specifiers. A
format specifier will be as [=%[*][width][modifiers]type=].

fprintf()

Description
The C library function int fprintf(FILE *stream, const char *format, ...) sends
formatted output to a stream.
Declaration
Following is the declaration for fprintf() function.
int fprintf(FILE *stream, const char *format, …)

Parameters

 stream -- This is the pointer to a FILE object that identifies the stream.
 format -- This is the C string that contains the text to be written to the
stream.It can optionally contain embedded format tags that are replaced
by the values specified in subsequent additional arguments and formatted
as requested.
fclose()

Description
The C library function int fclose(FILE *stream) closes the stream. All buffers are
flushed.

Declaration
Following is the declaration for fclose() function.
int fclose(FILE *stream)

Parameters

 stream - This is the pointer to a FILE object that specifies the stream to be
closed.

12
This method returns zero if the stream is successfully closed.On failure, EOF is
returned.

feof()

Description

The C library function int feof(FILE *stream) tests the end-of-file indicator for
the given stream.
Declaration

Following is the declaration for feof() function.


int feof(FILE *stream)

Parameters

 stream -- This is the pointer to a FILE object that identifies the stream.
This function returns a non-zero value when End-of-File indicator associated with the
stream is set, else zero is returned.

Example

#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE * fp1, *fp2;

fp1 = fopen ("file1.txt", "w+");


fp2 = fopen("file2.txt","r");

fprintf(fp1, "%s %s %s %d", "We", "are", "in", 2012);

while(1)
{
c = fgetc(fp2);
if( feof(fp2) )
{
break ;
}
fprintf(fp1,"%c", c);
}

13
fclose(fp1);
fclose(fp2)
return(0);
}

Algorithm:

1. Open the input program (INPUT.C) in read mode.


2. Open the output file in write mode ( SYMTAB.txt)
3. Intialize a varable for tracking the addresses of variables ( address=1000)
4. Read the input program until end of file is reached.
a) Read a word from a file.
b) Check whether it is one of the data type (int, float, char and double)
c) If it is data type
i. read the list of variables in the declaration.
ii. Check whether the symbol is already present in SYMTAB.txt
iii. Omit if it is already present.
iv. Otherwise, insert them with name, address and datatype into the output
file using fprintf function.
v. Update the address variable ( incr=1 for char data type, incr=2 for int data
type and incr=4 for float data type)
5. Close the files.

Sample Input and Output

INPUT.c

#include <stdio.h>
int main()
{
int sum, m1, m2, m3;
float avg;
char name[20];

14


}

SYMTAB.c

SYMBOL DATA-TYPE ADDRESS


sum int 2000
m1 int 2002
m2 int 2004
m3 int 2006
avg float 2008
name char 2012

Program and Rough Work

15
16
17
Viva Questions:

1. What is system software?


2. Give some applications of system software.
3. What is application software?
4. Compare system software and application software.
5. Define SIC machine
6. Mention the uses of symbol table.
7. Define Loader.

Sl. Marks
Module Max. Marks
No Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

Ex. No : 2 PASS ONE OF A TWO PASS ASSEMBLER

Date :

18
Aim:

To implement pass 1 algorithm of two-pass assembler.

Theory

Assembler's functions

1. Convert mnemonic operation codes to their machine language equivalents


2. Convert symbolic operands to their equivalent machine addresses
3. Decide the proper instruction format
4. Convert the data constants to internal machine representations
5. Write the object program and the assembly listing

Functions of PASS 1

 Assign addresses to all statements in the program


 Save the addresses assigned to all labels for use in Pass 2
 Perform assembler directives, including those for address assignment, such as
BYTE and RESW
Built-in C functions can be used
 fscanf()
 fprintf()
 feof()
 fclose()
 strcmp()

19
strcmp()

Description

The C library function int strcmp(const char *str1, const char *str2) compares the
string pointed to by str1 to the string pointed to by str2.
Declaration
Following is the declaration for strcmp() function.
int strcmp(const char *str1, const char *str2)

Parameters

 str1 -- This is the first string to be compared.


 str2 -- This is the second string to be compared.
Return Value
This function returned values are as follows:
 if Return value if < 0 then it indicates str1 is less than str2
 if Return value if > 0 then it indicates str2 is less than str1
 if Return value if = 0 then it indicates str1 is equal to str2

Example
#include <stdio.h>
#include <string.h>

int main ()
{
char str1[15];
char str2[15];
int ret;

strcpy(str1, "abcdef");
strcpy(str2, "ABCDEF");

ret = strcmp(str1, str2);

if(ret < 0)
{
printf("str1 is less than str2");

20
}
else if(ret > 0)
{
printf("str2 is less than str1");
}
else
{
printf("str1 is equal to str2");
}
return (0); }

Pseudo code of Pass 1 of two-pass Assembler

begin
if starting address is given
LOCCTR = starting address;
else
LOCCTR = 0;
while OPCODE != END do ;; or EOF
begin
read a line from the code
if there is a label
if this label is in SYMTAB, then error
else insert (label, LOCCTR) into SYMTAB
search OPTAB for the op code
if found
LOCCTR += N ;; N is the length of this
instruction (4 for MIPS)
else if this is an assembly directive
update LOCCTR as directed
else error
write line to intermediate file
end
program size = LOCCTR - starting address;
end

Pass1 Algorithm

1. Open the input file in read mode (INPUT.ASM).


2. Open the output file in write mode (INTERMEDIATE.txt)
3. Open a file for storing the symbols. ( SYMTAB.txt)

21
4. Read the input file until end of file is reached
a) Read a line from the input file using fscanf function.
b) Split it into three parts using strtok function ( LABEL, OPCODE and
OPERAND)
c) If ( strcmp(OPERATOR, “START”) == 0)
i. Initialize LOCCTR = atoi(OPERAND)
d) Otherwise
i. Initialize LOCCTR = 0
e) Check whether LABEL is not EMPTY
f) If so, write the LABEL and LOCCTR value into SYMTAB.txt using fprintf
function.
g) Write LOCCTR, LABEL , OPERATOR and OPERAND into the output file
(INTERMEDIATE.txt).
h) Update the LOCCTR by incrementing it by 3.
5. Close the files.

Sample Input and Output

INPUT.ASM

COPY START 1000


FIRST STL RETADR
CLOOP JSUB RDREC
LDA LENGTH
COMP ZERO
JEQ ENDFIL
JSUB WRREC
J CLOOP
ENDFIL LDA EOF
EOF BYTE C'EOF'
ZERO WORD 0
RETADR RESW 2
LENGTH RESW 1

SYMTAB.txt

22
SYMBOL ADDRESS
FIRST 1000
CLOOP 1003
ENDFIL 1015
EOF 1018
ZERO 101B
RETADR 101E
LENGTH 1021

INTERMEDIATE.txt

1000 COPY START 1000


1000 FIRST STL RETADR
1003 CLOOP JSUB RDREC
1006 LDA LENGTH
1009 COMP ZERO
100C JEQ ENDFIL
100F JSUB WRREC
1012 J CLOOP
1015 ENDFIL LDA EOF
1018 EOF BYTE C'EOF'
101B ZERO WORD 0
101E RETADR RESW 2
1021 LENGTH RESW 1

23
Program and Rough Work

24
25
26
Viva Questions

1. List out the activities of pass one assembler


2. What is meant by machine independent assembler features
3. Define Control Section
4. How the register to register instruction are translated in assembler
5. Compare : EXTREF and EXTDEF
6. What are assembler directives?
7. Differentiate BYTE, WORD from RESB and RESW.
8. What are the data structures used in pass 1?

Sl. Marks
Module Max. Marks
No Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

27
Ex. No : 3
PASS TWO OF A TWO PASS ASSEMBLER
Date :

Aim

To implement pass 2 algorithm of two-pass assembler.

Theory

Functions of pass-2

1. Assemble instructions (generate opcode and look up addresses)


2. Generate data values defined by BYTE, WORD
3. Perform processing of assembler directives not done during Pass 1
4. Write the object program and the assembly listing
Format of object program

Built-in C functions can be used

28
 fscanf()
 fprintf()
 feof()
 fclose()
 strtok()

strtok()

Description
The C library function char *strtok(char *str, const char *delim) breaks string str
into a series of tokens using the delimitrer delim.
Declaration
Following is the declaration for strtok() function.
char *strtok(char *str, const char *delim)

Parameters

 str -- The contents of this string are modified and broken into smaller strings
(tokens).
 delim -- This is the C string containing the delimiters. These may vary from one
call to another.
Return Value
This function returns a pointer to the last token found in string. A null pointer is
returned if there are no tokens left to retrieve.

Example
The following example shows the usage of strtok() function.
#include <string.h>
#include <stdio.h>

int main()
{
const char str[80] = "This is - www.tutorialspoint.com - website";
const char s[2] = "-";
char *token;

/* get the first token */


token = strtok(str, s);

29
/* walk through other tokens */
while( token != NULL )
{
printf( " %s\n", token );

token = strtok(NULL, s);


} return(0);}

Psudeuo code of PASS 2

Begin
read 1st input line
if OPCODE = „START‟ then
begin
write listing line
read next input line
end
write Header record to object program
initialize 1st Text record
while OPCODE != “END”
do
begin
if this is not comment line then
begin
search OPTAB for OPCODE
if found then
begin
if there is a symbol in OPERAND field then
begin
search SYMTAB for OPERAND
if found then
begin
store symbol value as operand address
else
begin
store 0 as operand address
set error flag (undefined symbol)
end
end (if symbol)

30
else
store 0 as operand address
assemble the object code instruction
else if
OPCODE = “BYTE” or “WORD” then
convert constant to object code
if object code doesn‟t fit into current Text record then
begin
Write text record to object code
initialize new Text record
end
add object code to Text record
end {if not comment}
write listing line
read next input line
end
write last listing line
End {Pass 2}

Here the first input line is read from the intermediate file. If the opcode is START, then
this line is directly written to the list file. A header record is written in the object
program which gives the starting address and the length of the program (which is
calculated during pass 1). Then the first text record is initialized. Comment lines are
ignored. In the instruction, for the opcode the OPTAB is searched to find the object
code. If a symbol is there in the operand field, the symbol table is searched to get the
address value for this which gets added to the object code of the opcode. If the address
not found thenzero value is stored as operands address. An error flag is set indicating it
as undefined. If symbol itself is not found then store 0 as operand address and the
object code instruction is assembled.

If the opcode is BYTE or WORD, then the constant value is converted to its equivalent
object code (for example, for character EOF, its equivalent hexadecimal value „454f46‟ is
stored). If the object code cannot fit into the current text record, a new text record is
created and the rest of the instructions object code is listed. The text records are written

31
to the object program. Once the whole program is assembled and when the END
directive is encountered, the End record is written.

Algorithm
1.Start the program
2. Initialize all the variables
3. Open a file by name
4. fp1=fopen("assmlist.dat","w");
fp2=fopen("symtab.dat","r");
fp3=fopen("intermediate.dat","r");
fp4=fopen("optab.dat","r");
5. Read the content of the file
6. If opcode is BYTE
if(strcmp(opcode,"BYTE")==0)
Then
fprintf(fp1,"%d\t%s\t%s\t%s\t",address,label,opcode,operand);
Else if opcode is WORD
7. else if(strcmp(opcode,"WORD")==0)
then
fprintf(fp1,"%d\t%s\t%s\t%s\t00000%s\n",address,label,opcode,operand,a);
8. else if((strcmp(opcode,"RESB")==0)(strcmp(opcode,"RESW")==0))
fprintf(fp1,"%d\t%s\t%s\t%s\n",address,label,opcode,operand);
else
fprintf(fp1,"%d\t%s\t%s\t%s\t%d\n",address,label,opcode,operand,code);
9.Finally terminate the of pass two of pass two assembler

Program and Rough Work

32
33
34
Viva Questions

1. What are the functions of PASS 2?


2. What is the use of location counter in Assembler?
3. Discuss the steps required to convert the source program into object program
4. State the use of assembler directive START
5. What is the structure of the object program?
6. Compare different records in object program.
7. What are the data structures used in PASS2?
8. How do you convert indexed instructions to object code?

Sl. Marks
Module Max. Marks
No Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

35
Ex. No : 4
IMPLEMENTATION OF SINGLE PASS ASSEMBLER
Date :

Aim:
To write a C program to implement a One pass assembler or Single Pass
assemblers.

Theory :

 One-pass assemblers are used when


o it is necessary or desirable to avoid a second pass over the source program
o the external storage for the intermediate file between two passes is slow or
is inconvenient to use
 Main problem: forward references to both data and instructions
 One simple way to eliminate this problem: require that all areas be defined
before they are referenced.
o It is possible, although inconvenient, to do so for data items.
o Forward jump to instruction items cannot be easily eliminated.

Load-and-go assembler
 Load-and-go assembler generates their object code in memory for immediate
execution.
 No object program is written out, no loader is needed.
 It is useful in a system oriented toward program development and testing such that
the efficiency of the assembly process is an important consideration

Forward Reference:
o Load-and-go assembler
 Omits the operand address if the symbol has not yet been defined
 Enters this undefined symbol into SYMTAB and indicates that it is
undefined
 Adds the address of this operand address to a list of forward
references associated with the SYMTAB entry
 Scans the reference list and inserts the address when the definition for
the symbol is encountered.
 Reports the error if there are still SYMTAB entries indicated
undefined symbols at the end of the program

36
 Search SYMTAB for the symbol named in the END statement and
jumps to this location to begin execution if there is no error

Example

37
Algorithm:

1. Read the first line of input file.


2. If the opcode is START ,initialize the location counter to the operand,
otherwise, initialize location counter to zero.
3. Read the next input line.
4. If there is symbol in label field, search for it in SYMTAB, if found and its value is
identified, then define its value and insert this value for the address
specified in the link, otherwise insert the symbol into SYMTAB.
5. Search for opcode in OPTAB
1.If found goto step 6.
2.If opcode is WORD ,add 3 to location counter,convert to object code.
3.If opcode is BYTE ,find the length of operand and add it to location
counter,convert the operand into object code.
4.If the opcode is RESW ,add 3*operand to location counter.
5.If code is RESB ,add operand value to location counter.
6.Goto step 8.
6. Search the SYMTAB for the operand
(i)If found, find the operand address.
(ii)Otherwise, set operand address as ‘0000’ and insert the operand into
SYMTAB with the value as *.Add the current address as link.
7. Assemble the object code with opcode and operand address.
8. Write the listing line and read next input line.
9. if the operand is END, goto 10,otherwise goto4.
10. Write the last listing line.

Program and Rough Work

38
39
40
Viva Questions

1. What is the use of load and go assembler


2. List out the different types of jump statements used in MASM assembler
3. What is the use of base register table in AIX assembler?
4. State the use of assembler directive CSECT and USE
5. Give the general format of define record.
6. Compare load and go assembler with two pass assembler?
7. What is the advantage of one-pass assembler?
8. What is multi-pass assembler?

Marks
Sl.No Module Max. Marks
Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

41
Ex. No : 5
IMPLEMENTATION OF TWO PASS MACRO
Date :

Aim

To implement a C program for Two Pass Macro.

Theory

A macro processor enables you to define and to use macros in your assembly programs.
When you define a macro, you provide text (usually assembly code) that you want to
associate with a macro name. Then, when you want to include the macro text in your
assembly program, you provide the name of the macro. The assembler replaces the
macro name with the text specified in the macro definition.

Advantages :

 The frequent use of macros can reduce programmer-induced errors


 The scope of symbols used in a macro is limited to that macro. You need not be
concerned about using a previously used symbol name.
 Macros are well-suited for creating simple code tables. Producing tables by hand
is both tedious and error-prone.

Algorithm

1. Get the statement from the input file


2. From the line read, Check if the opcode is he directive “MACRO”. If so then the
number of macro ‘n’ must be increased.
3. Repeat step1 and 2 until an end of file is encountered.
4. Open ‘n’ number of files in write mode. These files will later hold the body of the
‘n’ macros respectively.
5. Rewind the input file pointer.
6. If the opcode is “macro”

42
a. Enter the macro name present in the operand field into the array named
‘m’.
b. Write the line to the expanded output file.
c. Enter lines in the body of each macro nto the corresponding files already
opened in step4.
d. Write the body of each macro to the expanded output file also, until a
“mend” is reached.
7. Otherwise if the opcode is call the line must be a macro invocation statement so,
the macro body is retrieved from the corresponding file and written to the
expanded output file.
8. Write all the remaining lines directly to the expanded file.

43
Program and Rough Work

44
45
46
Viva Questions

1. List out the directives used in macro definition.


2. Which data structure is preferable for macro processor?
3. What is the use of macro time variable ?
4. Give the advantages of line by line processor?
5. How the macro is processed using two passes?
6. What is recursive macro processor?
7. Write a macro in C.
8. Mention about parameter substitution in macro invocation.
9. What is positional parameter?

Max. Marks
Sl.No Module
Marks Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

47
Ex. No : 6
IMPLEMENTATION OF SINGLE PASS MACRO
Date :

Aim
To implement a C program for Single Pass Macro.

Theory :

A macro may be thought of as a subroutine call with the exception that the code that
would be contained in the subroutine is included in–line at the point of the macro call.
Macros should not be used to replace subroutines. Each invocation of a subroutine
requires only the code necessary to call the subroutine. Each invocation of a macro
includes the assembly code associated with the macro in–line in the assembly program.
This can cause a program's size to grow rapidly if a large macro is used frequently.

A macro processor enables you to define and to use macros in your assembly programs.
When you define a macro, you provide text (usually assembly code) that you want to
associate with a macro name. Then, when you want to include the macro text in your
assembly program, you provide the name of the macro. The assembler replaces the
macro name with the text specified in the macro definition.
Macros provide several advantages when writing assembly programs.
• The frequent use of macros can reduce programmer-induced errors. A macro
allows you to define instruction sequences that are used repetitively throughout your
program. Subsequent use of the macro faithfully provides the same results each time. A
macro reduces the likelihood of errors introduced in repetitive programming sequences.
Of course, introduction of an error into a macro definition causes that error to
propagate through the program wherever the macro is used.
• The scope of symbols used in a macro is limited to that macro. You need not be
concerned about using a previously used symbol name.

48
• Macros are well-suited for creating simple code tables. Producing tables by hand
is both tedious and error-prone.

Algorithm

Step 1: Start the macro processor program


Step 2: Include the necessary header files and variable
Step 3: Open the three files
f1=macin.dat with read privilege
f2=macout.dat with write privilege
f3= deftab.dat with write privilege
Step 4:Get the variable form f1 file macin.dat for label,opcode,operand
Step 5:Read the variable until the opcode is not is equal to zero
Step 6:Then check if the opcode is equal to Macro if Macro
Then
Copy macroname=label
Step 7:Get the variable label ,opcode ,operand
Step 8:In these if condition perform the while loop until opcode is not equal to MEND
Step 9:Copy the variable
d[lines].lab=label
d[lines].opc=opcode
d[lines].oper=operand
and increase lines++;
Step 10:close while loop and if condtion
else if opcode is equal to macro name
Step 11:Perform the for loop from 0 to length
Step 12:fprint for d[i].lab,d[i].opc,d[i].oper
else if it is not match
fprintf(f2,"%s\t%s\t%s\n",label,opcode,operand);
Step 13:Finally terminate the program

49
INPUT FILE: MACIN.DAT
CALC START 1000
SUM MACRO **
** LDA #5
** ADD #10
** STA 2000
** MEND **
** LDA LENGTH
** COMP ZERO
** JEQ LOOP
** SUM **
LENGTH WORD 5
ZERO WORD 0
LOOP SUM **
** END **

OUTPUT FILES : MACOUT.DAT


CALC START 1000
** LDA LENGTH
** COMP ZERO
** JEQ LOOP
** LDA #5
** ADD #10
** STA 2000
LENGTH WORD 5
ZERO WORD 0
** LDA #5
** ADD #10
** STA 2000
** END **

DEFTAB.DAT
** LDA #5
** ADD #10
** STA 2000

50
Program and Rough Work

51
52
53
Viva Questions

1. Define macro processor.


2. Name some macro processors.
3. What are the uses of macro processors?
4. What is the symbol used to generate unique labels?
5. How is the nested macro call executed?
6. List out the factors for designing general purpose macro processors
7. Compare : single pass and multi pass macro assembler.
8. What are uses of ARGTAB, DEFTAB?

Max. Marks
Sl.No Module
Marks Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

54
Ex. No : 7
IMPLEMENTATION OF ABSOLUTE LOADER
Date :

Aim:
To write a C program to implement a absolute loader.

Theory :

An absolute loader is the simplest type of loader scheme that fits the general
model of loaders. The assembler produces the output in the same way as in the
"complier and go loader”. The assembler outputs the machine language translation of
the source program.
The assembler generates the object code equivalent of the source program but
the output is punched on to the cads forming the object decks instead of loading in
memory. The function of the loader is to read these cads and load them into memory
specified by the assembler. The four functions as performed in and absolute loader are :
1.Allocation
2.Linking
3.Relocation
4.Loading
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:.
 When subroutines are referenced, the programmer must specify their
address whenever they are called.
 The programmer must specifically tell the assembler the address where
the program is to be loaded

55
Algorithm:

Step 1: Start the program


Step 2: Assign the required variable
Step 3: Open the files
fp1=fopen("input.dat","r");
fp2=fopen("output.dat","w");
Step 4: Read the content
Step 5: Using while loop perform the loop until character is not equal to E
while(strcmp(input,"E")!=0)
Then compare the character is equal to H
If H then
fscanf(fp1,"%d",&start);
Step 6: Get length, and input
Else if the character is T
Step 7: Then perform the frprintf in fp1 for input file for ,
input[0],inuput[1] for address
input[2],inuput[3] for address+1
input[4],inuput[5] for address+2
Else if it is not H or T
Step 8: Then perform the frprintf in fp2 for output file for ,
input[0],inuput[1] for address
input[2],inuput[3] for address+1
input[4],inuput[5] for address+2
Step 9: Finally terminate the program

INPUT FILE
INPUT.DAT

H 1000 232
T 1000 142033 483039 102036
T 2000 298300 230000 282030 302015

56
E

OUTPUT FILE

OUTPUT.DAT

1000 14
1001 20
1002 33
1003 48
1004 30
1005 39
1006 10
1007 20
1008 36
2000 29
2001 83
2002 00
2003 23
2004 00
2005 00
2006 28
2007 20
2008 30
2009 30
2010 20
2011 15

Program and Rough Work

57
58
59
60
Viva Questions

1. What are the basic functions of dynamic linking ?


2. Define automatic library search.
3. What is the need of ESTAB?
4. List out the advantages of dynamic linking.
5. Define bit mask.

Max. Marks
Sl.No Module
Marks Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

61
Ex. No : 8
IMPLEMENTATION OF RELOCATION LOADER
Date :

Aim:
To write a C program to implement a relocation loader.

Theory :

Loaders that allow for program relocation are called relocating loaders/relative loaders.
There are two methods for this purpose.
1. In the first method, a modification record is used to describe each part of the object
code that must be changed when the program is relocated. There is one modification
record for each value that must be changed during relocation. Each modification record
specifies the starting address and length of the field whose value is to be altered. It then
describes the modification to be performed. This method is not well suited for all
machine architectures.

2. On a machine that primarily uses direct addressing and has a fixed instruction
format, different techniques is used. The text records are same as before except that
there is a relocation bit with each word of object code. These relocation bits are gathered
together into a bit mask following a length indicator in each text record. If the bit is set
to 1, the program’s starting address must be added to the word when program is
relocated. If bit is 0, then no modification is necessary. The bits for unused words are
also set to 0.
Algorithm
Step 1: Start the program
Step 2: Include the necessary header file and variable
Step 3: Open the two file for
Step 4: fp1= relinput.dat and give read
Step 5: fp2= reloutput.dat and give write
Step 6: Read the content
Step 7: Using while loop perform the loop until character is not equal to E
Step 8: while(strcmp(input,"E")!=0)
Step 9: If the character is H

62
Step 10: Get the variable add, length, and input
Step 11: Else if the character is T
Step 12: Get the variable address and bitmask
Step 13: And perform the for loop for starting zero to up to len
Step 14: Get the opcode ,addr and assign relocbit to bitmask
Step 15: If relocabit is zero Then
Step 16: actualadd=addr;
Step 17 :else Add the addr and star value
Step 18: Finally terminate the program
Sample Input & Output:
INPUT: RELINPUT.DAT
H 1000 200
T 1000 11001 14 1033 48 1039 90 1776 92 1765 57 1765
T 2011 11110 23 1838 43 1979 89 1060 66 1849 99 1477
E 1000
OUTPUT:
Enter the actual starting address :4000
RELOUTPUT.DAT
4000 144033
4003 484039
4006 901776
4009 921765
4012 574765
5011 234838
5014 434979
5017 894060
5020 664849
5023 991477

63
64
65
66
Viva Question
1. Compare relocatable with absolute loader.
2. What are the records used for indicating relocating addresses?
3. Write the structure of modification record.
4. What is control section linking?
5. Compare dynamic linking with dynamic loading.
6. List the advantages of relocatable loader.

Max. Marks
Sl.No Module
Marks Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

67
Ex. No : 9
IMPLEMENTATION OF PASS ONE OF LINKING LOADER
Date :

Aim

To perform pass one the Linking loader using c program

Theory

A program unit interacts with another by using the addresses latter's instructions and
data in its own instructions. To enable this, the program units must contain public
definitions and external references. A public definition in a program unit may be
reference in others. An external reference is a reference to symbol, which is not defined
in the program unit containing the reference.

EXTRN and ENTRY statements are used to deal with the above cases. ENTRY
statement lists the public definitions of program unit; which may be referenced in other
program units. EXTRN statement lists the symbols to which the external references are
made in the program units.

Before executing the program A, for each of its program units, every external reference
should bound to the correct link time address. This is called "LINKING”. Once it is
linked, it is said to be resolved.

A binary program is a machine language program consisting of a set of program units,


such that each program unit has been relocated to the memory area starting at its link
origin and linking has bee performed for each external reference in the program units.

Algorithm

68
Step 1: Start the program
Step 2: Include the necessary variables
Step 3: get PROGADDR from operating system
Step 4: set CSADDR to PROGADDR {for first control section}
Step5: Open the two file for
Step6: fp1= linkin.dat and give read
Step7: fp2= linkout .dat and give write
Step 8: Input the location where the program has to be loaded
Step 9: while not end of input do
begin
read next input record {Header record for control section}
set CSLTH to control section length
search ESTAB for control section name
if found then
set error flag {duplicate external symbol}
else
enter control section name into ESTAB with value CSADDR
Step 10: while record type ≠ 'E' do
begin
read next input record
if record type = 'D' then
for each symbol in the record do
begin
search ESTAB for symbol name
if found then
set error flag (duplicate external symbol)
else
enter symbol into ESTAB with value
(CSADDR + indicated address)

69
end {for}
end {while ≠ 'E'}
Step 11: add CSLTH to CSADDR {starting address for next control section
Step 12: end {while not EOF}
Step 13: Halt the program

70
71
Viva Questions

1. What are the data structures used for linking loader.


2. List the functions of linking loader.
3. Why do you need two passes for linking loader?
4. Compare linking loader with linkage editor.

Max. Marks
Sl.No Module
Marks Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

72
Ex. No : 10
IMPLEMENTATION OF PASS TWO OF LINKING LOADER
Date :

Aim:
To write a C program to generate a pass two of direct linking loader.

Theory :

• Modification record:
– Make the linking and relocation to be processed similarly.
• Two passes:
– Assign addresses to all external symbols
– Perform actual loading, relocation, and linking.
• Data structures used by linking loaders
– External symbol tab: ESTAB
• Name, address, and control session belonging to
• Also control sessions (name, address, length)
• Hash table
• ESTAB with control sessions and external symbols
– Program load address : PROGADDR
• The beginning address in memory where the
linked program is to be loaded.
• Supplied to loader by OS
– Control session address: CSADDR
• The starting address of the current control session.
• Added to all relative addresses in the control
session to get actual addresses.
– Execution starting address: EXECADDR.

Algorithm:

1: Read the header record from object program


2: Get the CSADDR for the correct control section from ESTAB
3: Read next input record
4: If the record type is END, goto step 8

73
5: If the record type is’T’, place the object code in location which is sum of CSADDR
and specified address
6: If the record type is M, search the ESTAB for symbol name.
(1) If found add or subtract symbol value at location CSADDR+ specified
address

(2) Otherwise display error message

7: Read next input record and goto step 4


8: If end of file is reached, Exit. Otherwise goto step 1

74
Max. Marks
Sl.No Module
Marks Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

75
Faculty Signature

76
Ex. No : 11
IMPLEMENTATION OF TEXT EDITOR
Date :
Aim

To implement a Simple Text Editor using c.

Theory :

A text editor is a type of program used for editing plain text files. Text editors are
often provided with operating systems or software development packages, and can be
used to change configuration files and programming language source code.

Operations on Text Editor


Cut, copy, and paste
 Text formatting
Undo and redo
Importing
Filtering
Syntax Highlighting

Types of text editors


Some text editors are small and simple, while others offer a broad and complex
range of functionality. For example, UNIX and Unix-like operating systems have the vi
editor (or a variant), but many also include the Emacs editor. Microsoft Windows
systems come with the very simple Notepad, though many people—especially
programmers—prefer to use one of many other Windows text editors with more
features. Under Apple Macintosh's classic Mac OS there was the native SimpleText,
which was replaced under OSX by Text Edit. Some editors, such as WordStar, have dual
operating modes allowing them to be either a text editor or a word processor.

77
Text editors geared for professional computer users place no limit on the size of the file
being opened. In particular, they start quickly even when editing large files, and are
capable of editing files that are too large to fit the computer's main memory. Simpler
text editors often just read files into an array in RAM. On larger files this is a slow
process, and very large files often do not fit.

The ability to read and write very large files is needed by many professional computer
users. For example, system administrators may need to read long log files.
Programmers may need to change large source code files, or examine unusually large
texts, such as an entire dictionary placed in a single file.

Some text editors include specialized computer languages to customize the editor
(programmable editors). For example, Emacs can be customized by programming in
Lisp. These usually permit the editor to simulate the keystroke combinations and
features of other editors, so that users do not have to learn the native command
combinations.
Many text editors for software developers include source code syntax
highlighting and automatic completion to make programs easier to read and write.
Programming editors often permit one to select the name of a subprogram or variable,
and then jump to its definition and back. Often an auxiliary utility like ctags is used to
locate the definitions.
Operations on Text Editor
• Cut, copy, and paste
Most text editors provide methods to duplicate and move text within the file, or
between files.
• Text formatting
Text editors often provide basic formatting features like line wrap, auto-indentation,
bullet list formatting, comment formatting, and so on.
• Undo and redo

78
As with word processors, text editors will provide a way to undo and redo the last edit.
Often—especially with older text editors—there is only one level of edit history
remembered and successively issuing the undo command will only "toggle" the last
change. Modern or more complex editors usually provide a multiple level history such
that issuing the undo command repeatedly will revert the document to successively
older edits. A separate redo command will cycle the edits "forward" toward the most
recent changes. The number of changes remembered depends upon the editor and is
often configurable by the user.
• Importing
Reading or merging the contents of another text file into the file currently being
edited. Some text editors provide a way to insert the output of a command issued to the
operating system's shell.
• Filtering
Some advanced text editors allow you to send all or sections of the file being
edited to another utility and read the result back into the file in place of the lines being
"filtered". This, for example, is useful for sorting a series of lines alphabetically or
numerically, doing mathematical computations, and so on.
• Syntax Highlighting
Another useful feature of many text editors is syntax highlighting, where the
editor can recognize or be instructed that you are writing in a particular language, such
as HTML or C++, and can color code your code for you, to break up text and easily
identify tags, etc.

79
Program and Rough Work

80
81
Viva Questions

82
1. Mention the features of word processors.
2. List all the components of editor structure.
3. What are the basic types of computing environment used in editor function?
4. Define travelling phase.
5. List the various types of text editors available

Max. Marks
Sl.No Module
Marks Obtained
1 Efficiency of Algorithm 10
2 Efficiency of program 10
3 Output 10
4 Technical Skill 10
5 Communication Skill 10
Total 50

Faculty Signature

83

You might also like