Notes of System Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

nSYSTEM PROGRAMMING NOTES

B.TECH(CSE)
SEM IV
CSE 206 B

UNIT 1
Introduction to Assemblers

Fundamental functions
translating mnemonic operation codes to their
machine language equivalents
assigning machine addresses to symbolic
labels
Machine dependency
different machine instruction formats and codes

Example Program
Purpose
reads records from input device (code F1)
copies them to output device (code 05)
at the end of the file, writes EOF on the outputdevice, then RSUB to the operating system
Example Program
Data transfer (RD, WD)
a buffer is used to store record
buffering is necessary for different I/O rates
the end of each record is marked with a null
character (0016)
the end of the file is indicated by a zero-length
record
Subroutines (JSUB, RSUB)
RDREC, WRREC
save link register first before nested jump
Assembler Directives
Pseudo-Instructions
Not translated into machine instructions
Providing information to the assembler
Basic assembler directives
START
END
BYTE
WORD
RESB
RESW
Assemblers functions
Convert mnemonic operation codes to their machine language equivalents
Convert symbolic operands to their equivalent machine addresses
Build the machine instructions in the proper format

Convert the data constants to internal machine representations


Write the object program and the assembly listing
Definition of Loader:
Loader is utility program which takes object code as input prepares it for execution and loads the
executable code into the memory. Thus loader is actually responsible for initiating the execution
process.
Functions of Loader:
The loader is responsible for the activities such as allocation, linking, relocation and loading
1) It allocates the space for program in the memory, by calculating the size of the program. This
activity is called allocation.
2) It resolves the symbolic references (code/data) between the object modules by assigning all
the user subroutine and library subroutine addresses. This activity is called linking.
3) There are some address dependent locations in the program, such address constants must be
adjusted according to allocated space, such activity done by loader is called relocation.
4) Finally it places all the machine instructions and data of corresponding programs and
subroutines into the memory. Thus program now becomes ready for execution, this activity is
called loading.
(Macro processors)
Introduction:
A macro represents a commonly used group of statements in thesource pro ramming language.
The macro processor replaces each macroinstruction with the corresponding group of source
language statements.
This is called expanding of macros.
Basic Macro Processor Functions:
We study the fundamental functions that are commonly used by all macro
Macro Definition and Expansion
Macro is a unit of specification for program generation throughexpansion.
A macro consists of a name, a set of formal parameters and body ofcode.
Macro expansion is a macro name with a set of formal parameters isreplaced by some code.
Lexical expansion is replacement of a character string by anothercharacter string during
program generation.
Semantic expansion is generation of instructions tailored to therequirements of specific usage.
Macro definition consists of
i) macro prototype ii) one of more model iii) macro preprocessor
Macro definition is in between a macro header statement and a macro estatement.
Syntax of macro prototype statement
Macro Expansion
Macro call leads to macro expansion.
Macro call statement is replaced by a sequence of assembly statement inmacro expansion.
Two key notions are used in macro expansion
a) Expansion time control flow

b) Lexical substitution
Algorithm for macro expansion
1. Initialize the macro expansion counter (MEC)
2. Check the statement which is pointed by MEC is not a MEND
3. Exit from the macro expansion
RDBUFF and WRBUFF are the two macro instruction used in the Fig.

SIC/XE program. MACRO and MEND are the two new assemblerdirectives also used. RDBUFF
is the name of macro which is in the labelfield. The entry in the operand field identify the
parameters of the macroinstruction.
Each parameter begins with the character & which facilities thesubstitution of parameters
during macro expansion.
The macro name and parameters define a pattern or prototype for themacro instruction used by
the programmer. Body of the macro definitionis defined by the MACRO' directive statements.
Macro expansiongenerate these statements. End of the macro definition is defined by the
MEND assembler directive.
In the main program . Macro invocation statement that gives the nameof the macro instruction
being invoked and the arguments to be used inexpanding the macro .
Each macro invocation statement has been expanded into the statementsthat form the body of
the macro, with the arguments from the macroinvocation substituted for the parameters in the
macro prototype.
Parameters and arguments, both are associated with one anotheraccording to their positions.
The argument F1 is substituted for the parameter &INDEV whenever itoccurs in the body of
the macro. BUFFER is substituted for &BUFADRand &LENGTH is substituted for &RECLTH.
After macro processing, the expanded file can be used as input to theassembler.
Macro Processor Algorithm and Data Structures:
For designing two pass macro processor, all macro definitions areprocessed during the first pass
and all macro invocation statements areexpanded during the second pass. This type of two pass
macro processorwould not allow the body of one macro instruction to contain definitions
of other macros. The reason behind is that, all macros defined during thefirst pass before any
macro invocation were expanded.
Following example shows the definition of macros within a macro body.
The body of first macro (MACROS) contains statements that defineRDBUFF WRBUFF and
other macro instructions for a SIC system.Second macro instruction body (MACROX) defines
these same macrosfor a SIC\XE system. The same program could run on either a standard

SIC machine or a SIC\XE machine. Invocation of MACROS orMACROX is only changed for
use. Defining MACROS or MACROXdoes not define RDBUFF and other macro instructions.
These definitionsare processed only when an invocation 0MACROS or MACROX is
expanded.
Macro processor uses three main data structure.
1. Definition table (DEFT AB)
2. Name table (NAMTAB)
3. Argument table (ARGT AB)
Definition table stores macro definitions. It contains the macroprototype and the statements that
make up the macro body. The macronames are also entered into NAMT AB, which serves as an
index toDEFT AB.
When macro instruction defined, NAMTAB contains pointers to thebeginning and end of the
definition in DEFTAB.
Argument table (ARGT AB) is used during the expansion of macroinvocations. When a macro
invocation statement is recognized theargument are stored in ARGTAB according to their
position in theargument list.
Compilers
A compiler is a program that translates a sentencea. from a source language (e.g. Java,
Scheme, LATEX)
b. into a target language (e.g. JVM, Intel x86, PDF)
c. while preserving its meaning in the process
Compiler design has a long history (FORTRAN 1958)
a. lots of experience on how to structure compilers
b. lots of existing designs to study (many freely available)
c. take CS 152: Compiler Design for some of the details. . .

SOFTWARE TOOLS
A software tool is a system program which
a) Interfaces a program with the entity generating its input data or
b) Interfaces the result of a program with the entity consuming them.
Figure below shows the schematic of a software tool.

Program Development: Step in the program developments are


1) Program design, coding and documentation
2) Preparation of program in machine readable form.
3) Program translation linking and loading
4) Program testing debugging
5) performance tuning
6) Reformatting the data or results of program to suit other programs.
1. Program Design and Coding
Tools used for program design and coding are
a)Program generators
b)Programming environments.
A program generator generates a program which performs a set of functions described in its
specification.
A programming environment supports program cooing by incorporating awareness of the
programming language syntax and semantics in the language editor.
2. Program Entry and Editing
In this, text editors are used as front ends tool. The editor operates m two mode:
Command mode and data mode
In the command mode, it accepts user commands specifying the editing function' to be
performed. In the data mode, the user keys in the text to added to the file.
3. Program Testing and Debugging
The important parameters are the selection of test data for the program analysis of test result to
detect errors and debugging.
For program testing, the selection of test data for program and analysis of test results to detect
error if any is important.
User uses the software tools for this purpose.
1) Test data generators.
2) Automated test drivers.
3) Debug monitors.
4) Source code control.
Test data generators help the programmer in selecting test data.
Regression testing is done through automated test drives. in this, program correctness is
verified by subjecting it to a standard set of tests after every modification.
Obtaining the information about localization of error, debug monitor is used.
Source code control system help to keep track of modification in the source code.
4. Enhancement of Program Performance Two factors affects the program efficiency. These
are:
a)Efficiency of the algorithm
b)Efficiency of its coding
An optimizing compiler can improve efficiency of the code but it cannot improve efficiency of
the algorithm. Only a program designer can improve efficiency of an algorithm by rewriting it.
3
5. Program Documentation Most programming projects suffer from lack of up to date
documentation~ Automatic documentation tools are motivated by the desire to overcome this
deficiency.

These tools work on the source program to produce different forms of documentation e.g. flow
charts
6. Design for Software Tools
Program preprocessing techniques are used to support static analysis of programs. Program
instrumentation implies insertion of statements in a program. The instrumented program is
translated using a standard translator.
Figure below shows the schematic of software tools using the techniques of interpretation and
program generation.
Interpreter based tools suffer from poor efficiency and poor portability, since an interpreter base
tool is only as portable as the interpreter it uses. A generate program is more efficient and can be
made portable

TEXT EDITORS:
These are the primary interface to the computer for all types of Knowledge
workers as they
compose, organize, study and manipulate computer-based information.

1) Give an overview of the editing process.


An interactive editor is a computer program that allows a user to create and revise a
target document.
The term document includes objects such as computer programs, texts, equations,
tables, diagrams, line
arts and photographs-anything that one might find on a printed page.
Text editor is one in which the primary elements being edited are character strings
of the target text.
The document editing process is an interactive user-computer dialogue designed to
accomplish four
tasks:
1) Select the part of the target document to be viewed and manipulated
2) Determine how to format this view on-line and how to display it.
3) Specify and execute operations that modify the target document.
4) Update the view appropriately.
Traveling Selection of the part of the document to be viewed and edited. It
involves first traveling

through the document to locate the area of interest such as next


screenful,bottom, and find
pattern Traveling specifies where the area of interest is;
Filtering: The selection of what is to be viewed and manipulated is controlled by
filtering.
Filtering extracts the relevant subset of the target document at the point of interest,
such as next
screenful of text or next statement.
Formatting: Formatting then determines how the result of filtering will be seen as
a visible
representation (the view) on a display screen or other device.
Editing: In the actual editing phase, the target document is created or altered with
a set of operations
such as insert, delete, replace, move or copy. Manuscript oriented editors operate
on elements such as
single characters, words, lines, sentences, and paragraphs; Program-oriented
editors operates on
elements such as identifiers, key words and statements
2) Explain the User-Interface of an Editor.
The user of an interactive editor is presented with a conceptual model of the editing
system. The
model is an abstract framework on which the editor and the world on which the
operations are
based. Some of the early line editors simulated the world of 80-character card
image lines.
The Screen-editors define a world in which a document is represented as a
quarter-plane of text
lines. Unbounded both down and to the right. The user sees ,through a cutout ,only
a rectangular
subset of this planeon a multi line display terminal. The cutout can be move left or
right ,and up or
down ,to display other portions of the document. The user interface is also
concerned with the input
devices,the output devices,and the interaction language of the system.
Input Devices: The input devices are used to enter elements of text being edited
,to enter
commands,and to designate editable elements.

System Software (Text Editors) www.examengine.info


INPUT DEVICES are categorized as:
1)Text devices
2)Button devices
3)Locator devices
1)Text or string devices are typically typewriter like keyboards on which user
presses and release
keys ,sending unique code for each key. Virtually all computer key boards are of the
QWERTY type.
2)Button or Choice devices generate an interrupt or set a system flag,usually
causing an invocation
of an associated application program. Also special function keys are also available
on the key board.

3)Locator devices : They are two-dimensional analog-to-digital converters that


position a cursor
symbol on the screen by observing the users movement of the device. The most
common such
devices are the mouse and the tablet.
The Data Tablet is a flat ,rectangular,electromagnetically sensitive panel. Either
the ballpoint pen
like stylus or apuck,a small device similar toa mouse are moved over the surface.
The tablet returns to
a system program the co-ordinates of the position on the data tablet at which the
stylus or puck is
currently located. The program can then map these data-tablet coordinates to
screen coordinates and
move the cursor to the corresponding screen position.
Text devices with arrow(Cursor) keys can be used to simulate locator devices. Each
of these keys
shows an arrow that points up,down,left,orright.Pressing an arrow key typically
generates an
appropriate character sequence ,the program interpretsw this sequence and moves
the cursor in the
direction of the arrow on the key pressed.
Voice-input Devices : ,which translate spoken words to their textual equivalents,may
prove to be the
text input devices of the future
OUTPUT DEVICES
The output devices let the user view the elements being edited and the result of the
editing operations.
The first output devices were teletypewriters and other character-printing terminals
that generated
output on paper. Next CRT(Cathode Ray Tube) technology which uses CRT screen
essentially to simulate
the hard-copy teletypewriter. Todays advanced CRT terminals use hardware
assistance for such features
as moving the cursor,inserting and deleting characters and lines,and scrolling lines
and pages.
Interaction Language: The interaction language of the text editor is generally one
of several common
types.
1) The typing oriented or text command-oriented method
is the oldest of the major editing interfaces. The user communicate with the editor
by typing text
stringsboth for command names and and for operands. These strings are sent to the
editor and are
usually echoed to the output device. Typed specification often requires the user to
remember the exact
form of all commands ,or at least their abbreviations. He Help facility have to be
used or manuals have to
be refered. Time consuming for in-experienced users.
2) Function key interfaces :
Each command is associated with marked key on the key board

Eg. Insert key,Shiftkey,Control key

System Software (Text Editors) www.examengine.info

3)Menu oriented interfaces


A menu is a multiple choice set of text strings or icons which are graphical symbols
that represent objects
or operations
The user can perform actions by selecting items for the menus
The editor prompts the user with a menu
One problem with menu oriented system can arise when there are many possible
actions and several
choices are required to complete an action. The display area of the menu is rather
limited.
3) Explain with a neat diagram the structure of an Editor.
Typical Editor Structure

Most Text editors have a structure similar to that shown above.


The command Language Processor accepts input from the users input
devices,and analyzes the tokens
and syntactic structure of the commands. It functions much like the lexical and
syntactic phases of a

compiler. The command language processor may invoke the semantic routines
directly. In a text
editor,these semantic routines perform functions lsuch as editing and viewing. The
semantic routines
involve travelling,editing,viewing,and display functions. Editing operations are
always specified by the
user. In editing a document,the start of the area to be edited is determined by the
current editing
pointer maintained by the editing component ,which is the collection of modules
dealing with editing
tasks. The current editing pointer can be set or reset explicitly by the user using
travelling commands
,such as next paragraph and next screen,or implicitly as a side effect of the previous
editing operation
such as delete paragraph. The traveling component of the editor actually performs
the setting of the
current editing and viewing pointers,and thus determines the point at which the
viewing and /or editing
filtering begins. hen the user issues an editing command,the editing component
invokes the editing filter.
This component filters the document to generate a new editing buffer based on the
current editing ponter
as well as on the editing filter parameters. These parameters,which are specified by
both by the user and
the system,provide information such as the range of the text that can be affected
by an operation.
Filtering may consist of the selection of contiguous characters beginning at the
current point.

Similarly,in viewing a document ,the start of the area to be viewed is determined by


the current
viewing pointer. This pointer is maintained by the viewing component of the
editor,which is a collection
of modules responsible for determining the next view. The current viewing pointer
can be set or
resetexplicitly by the user or implicitly by the systemas a result of previous editing
operation.
When the display needs to be updated,the viewing component invokes the viewing
filter. This componet
filters the document to generate a new viewing buffer based on the current viewing
pointer as well as on
the viewing filter parameters. In Line editors,the viewing buffer may contain the
current line; in screen
editors,this buffer may contain rectangular cut out of the quarter-plane of text. This
viewing buffer is then
passed to the display component of the editor,which produces a display by mapping
the buffer to a
rectangular subset of the screen,usually called a window.

The editing and viewing buffers, while independent, can be related in many ways.
Ina simplest case
,they are identical:theuser edits the material directly on the screen.On the other
hand ,the editing and
viewing buffers may be completely disjoint. EG The user of a certain editor might
travel to line 75,and
after viewing it,decide to change all occurrences of ugly duckling to swan in
lines 1 through 50 of the
file by using a change command such as[1,50] c/ugly duckling/swan/
As apart of the editing command there is implicit travel to the first line of the file.
Lines 1 through 50 are
then filtered from the document to become the editing buffer.Successive
substitutions take place in this
editing buffer without correspoing updates of the view

Debug Monitors:
Dynamic debugging facility is provided by the debug monitors. It includes
following activities.
1)Setting breakpoints in the program.
2) Initiating a debug conversation when control reaches a breakpoint.
3)Displaying values of variables.
4)Assigning new values to variables.
5)Testing user defined assertions and predicates involving program variables.
When the user a commands to set a breakpoint the debug monitor instruments
the program to introduce a sensing instruction before the start of the statement at
breakpoint.
The debug monitor function can be easily implemented in an interpreter.
When a user gives a command to set a breakpoint at statement 150, The debug
monitor instruments the program to introduce the instruction.
<SI-instrn><code>in place of the no-op instructions preceding no-op 150.
The debug monitors requires two kind of information regarding the user
program.
a) Starting address of program statements in the complied code.
b) Program variables name and address.
Dynamic debugging of a program Following sequence of step involved .in
dynamic debugging of a program.
1)The user compiles the program under the debug option. The compiler produces
two file i.e.
a)Complied code file
b)Debug information file
2)The user activates the debug monitor and indicates the name of program to be
debugged. Debug monitor opens the corresponding two files.

2)User indicates the debug requirements i.e. a list of breakpoints and action to
performed at breakpoints. Debug monitor builds a debug table. This table
_contains, <statement number, debug action.>'
3)The instrumented program gets the control and executes up to a breakpoint.
2)When <SCinstrn> is excuted, software interrupt is generated and control is given
to the debug monitor. Debug monitor construct the debug table and perform the
debug actions associated with it.
Control now returns to the u program.
1) 3)Steps (4) and (5) are repeated until the end of the debug session.

UNIT 2
Two Pass Assembler
Pass 1
Assign addresses to all statements in the program
Save the values assigned to all labels for use in Pass 2
Perform some processing of assembler directives
Pass 2
Assemble instructions
Generate data values defined by BYTE, WORD
Perform processing of assembler directives not done inPass 1
Write the object program and the assembly listing
Two Pass Assembler

Operation Code Table (OPTAB)

Data Structures

Symbol Table (SYMTAB)


Location Counter(LOCCTR)
OPTAB (operation code table)
Content
menmonic, machine code (instruction format,length) etc.
Characteristic
static table
Implementation
array or hash table, easy for search
SYMTAB (symbol table)
Content
label name, value, flag, (type, length) etc.
Characteristic
dynamic table (insert, delete, search)
Implementation
hash table, non-random keys, hashing function
Object Program
Header
Col. 1 H
Col. 2~7 Program name
Col. 8~13 Starting address (hex)
Col. 14-19 Length of object program in bytes (hex)
Text
Col.1 T
Col.2~7 Starting address in this record (hex)
Col. 8~9 Length of object code in this record in bytes (hex)
Col. 10~69Object code (69-10+1)/6=10 instructions
End
Col.1 E
Col 2~7 Address of 16
Col.2 first executable instruction (hex)
Assembler Design
Machine Dependent Assembler Features
instruction formats and addressing modes
program relocation
Machine Independent Assembler Features
literals
symbol-defining statements
expressions
program blocks
control sections and program linking

Machine-dependent Assembler Features


Instruction formats and addressing modes
Program relocation
Instruction Format and Addressing Mode
SIC/XE
PC-relative or Base-relative addressing: op m
Indirect addressing: op @m
Immediate addressing: op #c
Extended format: +op m
Index addressing: op m,x
register-to-register instructions
larger memory -> multi-programming (program allocation)
Translation
Register translation
register name (A, X, L, B, S, T, F, PC, SW) and their
values (0,1, 2, 3, 4, 5, 6, 8, 9)
preloaded in SYMTAB
Address translation
Most register-memory instructions use program
counter relative or base relative addressing
Format 3: 12-bit address field
base-relative: 0~4095
pc-relative: -2048~2047
Format 4: 20-bit address field
SYMTAB
None of the relative terms may enter into a multiplication or division operation
Errors:
BUFEND+BUFFER
100-BUFFER
3*BUFFER
The type of an expression
keep track of the types of all symbols defined in
the program Symbol Type Value
Program Blocks
Program blocks
refer to segments of code that are rearranged
within a single object program unit
USE [blockname]
At the beginning, statements are assumed tobe part of the unnamed (default) block
If no USE statements are included, the entireprogram belongs to this single block
Example: Figure 2.11
Each program block may actually containseveral separate segments of the sourceprogram

Program Blocks - Implementation


Pass 1
each program block has a separate location counter
each label is assigned an address that is relative to thestart of the block that contains it
at the end of Pass 1, the latest value of the locationcounter for each block indicates the length
of that block
the assembler can then assign to each block a startingaddress in the object program
Pass 2
The address of each symbol can be computed byadding the assigned block starting address
and therelative address of the symbol to that block
Program Readability
Program readability
No extended format instructions.
No needs for base relative addressing
LTORG is used to make sure the literals areplaced ahead of any large data areas (line 253)
Object code
It is not necessary to physically rearrange thegenerated code in the object program
Control Sections and Program Linking
Control Sections
are most often used for subroutines or otherlogical subdivisions of a program
the programmer can assemble, load, andmanipulate each of these control sectionsseparately
instruction in one control section may need torefer to instructions or data located in another
section
because of this, there should be some meansfor linking control sections together
One-Pass Assemblers
Main problem
forward references
data items
labels on instructions
Solution
data items: require all such areas be defined
before they are referenced
labels on instructions: no good solution
Two types of one-pass assembler
load-and-go:
produces object code directly in memory forimmediate execution
the other:
produces usual kind of object code for laterexecution
Load-and-go Assembler
Characteristics
Useful for program development and testing

Avoids the overhead of writing the objectprogram out and reading it back
Both one-pass and two-pass assemblers canbe designed as load-and-go.
However one-pass also avoids the over headof an additional pass over the source program
For a load-and-go assembler, the actualaddress must be known at assembly time, we can use
an absolute program
Forward Reference in One-pass Assembler
For any symbol that has not yet beendefined
1. omit the address translation
2. insert the symbol into SYMTAB, and mark thissymbol undefined
3. the address that refers to the undefinedsymbol is added to a list of forward
referencesassociated with the symbol table entry
4. when the definition for a symbol isencountered, the proper address for thesymbol is then
inserted into any instructionsprevious generated according to the forwardreference list
Load-and-go Assembler (Cont.)
At the end of the program
any SYMTAB entries that are still marked with *indicate undefined symbols
search SYMTAB for the symbol named in theEND statement and jump to this location to
begin execution
The actual starting address must bespecified at assembly time
Producing Object Code
When external working-storage devices are not available or too slow (for the
intermediate filebetween the two passes
Solution:
When definition of a symbol is encountered, the
assembler must generate another Tex record with the
correct operand address
The loader is used to complete forward references that
could not be handled by the assembler
The object program records must be kept in their
original order when they are presented to the loader
Multi-Pass Assemblers
Restriction on EQU and ORG
no forward reference, since symbols valuecant be defined during the first pass
Example
Use link list to keep track of whose valuedepend on an undefined symbol

UNIT 3
(Macro processors)
Introduction:

A macro represents a commonly used group of statements in thesource pro ramming language.
The macro processor replaces each macroinstruction with the corresponding group of source
language statements.
This is called expanding of macros.
Basic Macro Processor Functions:
We study the fundamental functions that are commonly used by all macro
Macro Definition and Expansion
Macro is a unit of specification for program generation throughexpansion.
A macro consists of a name, a set of formal parameters and body ofcode.
Macro expansion is a macro name with a set of formal parameters isreplaced by some code.
Lexical expansion is replacement of a character string by anothercharacter string during
program generation.
Semantic expansion is generation of instructions tailored to therequirements of specific usage.
Macro definition consists of
i) macro prototype ii) one of more model iii) macro preprocessor
Macro definition is in between a macro header statement and a macro estatement.
Syntax of macro prototype statement
Macro Expansion
Macro call leads to macro expansion.
Macro call statement is replaced by a sequence of assembly statement inmacro expansion.
Two key notions are used in macro expansion
a) Expansion time control flow
b) Lexical substitution
Algorithm for macro expansion
1. Initialize the macro expansion counter (MEC)
2. Check the statement which is pointed by MEC is not a MEND
3. Exit from the macro expansion
RDBUFF and WRBUFF are the two macro instruction used in the Fig.

SIC/XE program. MACRO and MEND are the two new assemblerdirectives also used. RDBUFF
is the name of macro which is in the labelfield. The entry in the operand field identify the
parameters of the macroinstruction.
Each parameter begins with the character & which facilities thesubstitution of parameters
during macro expansion.

The macro name and parameters define a pattern or prototype for themacro instruction used by
the programmer. Body of the macro definitionis defined by the MACRO' directive statements.
Macro expansiongenerate these statements. End of the macro definition is defined by the
MEND assembler directive.
In the main program . Macro invocation statement that gives the nameof the macro instruction
being invoked and the arguments to be used inexpanding the macro .
Each macro invocation statement has been expanded into the statementsthat form the body of
the macro, with the arguments from the macroinvocation substituted for the parameters in the
macro prototype.
Parameters and arguments, both are associated with one anotheraccording to their positions.
The argument F1 is substituted for the parameter &INDEV whenever itoccurs in the body of
the macro. BUFFER is substituted for &BUFADRand &LENGTH is substituted for &RECLTH.
After macro processing, the expanded file can be used as input to theassembler.
Macro Processor Algorithm and Data Structures:
For designing two pass macro processor, all macro definitions areprocessed during the first pass
and all macro invocation statements areexpanded during the second pass. This type of two pass
macro processorwould not allow the body of one macro instruction to contain definitions
of other macros. The reason behind is that, all macros defined during thefirst pass before any
macro invocation were expanded.
Following example shows the definition of macros within a macro body.
The body of first macro (MACROS) contains statements that defineRDBUFF WRBUFF and
other macro instructions for a SIC system.Second macro instruction body (MACROX) defines
these same macrosfor a SIC\XE system. The same program could run on either a standard
SIC machine or a SIC\XE machine. Invocation of MACROS orMACROX is only changed for
use. Defining MACROS or MACROXdoes not define RDBUFF and other macro instructions.
These definitionsare processed only when an invocation 0MACROS or MACROX is
expanded.
Macro processor uses three main data structure.
1. Definition table (DEFT AB)
2. Name table (NAMTAB)
3. Argument table (ARGT AB)
Definition table stores macro definitions. It contains the macroprototype and the statements that
make up the macro body. The macronames are also entered into NAMT AB, which serves as an
index toDEFT AB.
When macro instruction defined, NAMTAB contains pointers to thebeginning and end of the
definition in DEFTAB.
Argument table (ARGT AB) is used during the expansion of macroinvocations. When a macro
invocation statement is recognized theargument are stored in ARGTAB according to their
position in theargument list.

Loaders and Linkers


Definition of Loader:

Loader is utility program which takes object code as input prepares it for execution and loads the
executable code into the memory. Thus loader is actually responsible for initiating the execution
process.
Functions of Loader:
The loader is responsible for the activities such as allocation, linking, relocation and loading
1) It allocates the space for program in the memory, by calculating the size of the program. This
activity is called allocation.
2) It resolves the symbolic references (code/data) between the object modules by assigning all
the user subroutine and library subroutine addresses. This activity is called linking.
3) There are some address dependent locations in the program, such address constants must be
adjusted according to allocated space, such activity done by loader is called relocation.
4) Finally it places all the machine instructions and data of corresponding programs and
subroutines into the memory. Thus program now becomes ready for execution, this activity is
called loading.
Loader Schemes:
Based on the various functionalities of loader, there are various types of loaders:
1) compile and go loader: in this type of loader, the instruction is read line by line, its
machine code is obtained and it is directly put in the main memory at some known address. That
means the assembler runs in one part of memory and the assembled machine instructions and
data is directly put into their assigned memory locations. After completion of assembly process,
assign starting address of the program to the location counter. The typical example is WATFOR77, its a FORTRAN compiler which uses such load and go scheme. This loading scheme is
also called as assemble and go.
Advantages:
This scheme is simple to implement. Because assembler is placed at one part of the memory
and loader simply loads assembled machine instructions into the memory.
Disadvantages:
In this scheme some portion of memory is occupied by assembler which is simply a wastage of
memory. As this scheme is combination of assembler and loader activities, this combination
program occupies large block of memory.
There is no production of .obj file, the source code is directly converted to executable form.
Hence even though there is no modification in the source program it needs to be assembled and
executed each time, which then becomes a time consuming activity.
It cannot handle multiple source programs or multiple programs written in different languages.
This is because assembler can translate one source language to other target language.
For a programmer it is very difficult to make an orderly modulator program and also it becomes
difficult to maintain such program, and the compile and go loader cannot handle such
programs.
The execution time will be more in this scheme as every time programis assembled and then
executed.
2) General Loader Scheme: in this loader scheme, the source program is converted to object
program by some translator (assembler). The loader accepts these object modules and puts
machine instruction and data in an executable form at their assigned memory. The loader
occupies some portion of main memory.
Advantages:

The program need not be retranslated each time while running it. This is because initially when
source program gets executed an object program gets generated. Of program is not modified,
then loader can make use of this object program to convert it to executable form.
There is no wastage of memory, because assembler is not placed in the memory, instead of it,
loader occupies some portion of the memory. And size of loader is smaller than assembler, so
more memory is available to the user.
It is possible to write source program with multiple programs and multiple languages, because
the source programs are first converted to object programs always, and loader accepts these
object modules to convert it to executable form.
3) Absolute Loader: Absolute loader is a kind of loader in which relocated object files are
created, loader accepts these files and places them at specified locations in the memory. This type
of loader is called absolute because no relocation information is needed; rather it is obtained
from the programmer or assembler. The starting address of every module is known to the
programmer, this corresponding starting address is stored in the object file, then task of loader
becomes very simple and that is to simply place the executable form of the machine instructions
at the locations mentioned in the object file. In this scheme, the programmer or assembler should
have knowledge of memory management. The resolution of external references or linking of
different subroutines are the issues which need to be handled by the programmer. The
programmer should take care of two things: first thing is : specification of starting address of
each module to be used. If some modification is done in some module then the length of that
module may vary. This causes a change in the starting address of immediate next .modules, its
then the programmer's duty to make necessary changes in the starting addresses of respective
modules. Second thing is ,while branching from one segment to another the absolute starting
address of respective module is to be known by the programmer so that such address can be
specified at respective JMP instruction. For example
Line number
1 MAIN START 1000
..
..
..
1 JMP 5000
16 STORE ;instruction at location 2000
END
5 Dr.ShaimaaH.Shaker
1 SUM START 5000
2
20 JMP 2000
21 END
In this example there are two segments, which are interdependent. At line
number 1 the assembler directive START specifies the physical starting address that can be used
during the execution of the first segment MAIN. Then at line number 15 the JMP instruction is
given which specifies the physical starting address that can be used by the second segment. The
assembler creates the object codes for these two segments by considering the stating addresses of
these two segments. During the execution, the first segment will be loaded at address 1000 and
second segment will be loaded at address 5000 as specified by the programmer. Thus the
problem of linking is manually solved by the programmer itself by taking care of

the mutually dependant dresses. As you can notice that the control is correctly transferred to the
address 5000 for invoking the other segment, and after that at line number 20 the JMP instruction
transfers the control to the location 2000, necessarily at location 2000 the instruction STORE
of line number 16 is present. Thus resolution of mutual references and linking is done by the
programmer. The task of assembler is to create the object codes for the above segments and
along with the information such as starting address of the memory where actually the object code
can be placed at the time of execution. The absolute loader accepts these object modules from
assembler and by reading the information about their starting addresses, it will actually place
(load) them in the memory at specified addresses.
The entire process is modeled in the following figure. Thus the absolute loader is simple to
implement in this scheme
l) Allocation is done by either programmer or assembler
2)Linking is done by the programmer or assembler
3)Resolution is done by assembler
4)Simply loading is done by the loader
As the name suggests, no relocation information is needed, if at all it is required then that task
can be done by either a programmer or assembler
Advantages:
1. It is simple to implement
2. This scheme allows multiple programs or the source programs written different languages. If
there are multiple programs written in different languages then the respective language assembler
will convert it to the language and a common object file can be prepared with the entire ad
resolution.
3. The task of loader becomes simpler as it simply obeys the instruction regarding where to place
the object code in the main memory.
4. The process of execution is efficient.
Disadvantages:
1. In this scheme it is the programmer's duty to adjust all the inter segment addresses and
manually do the linking activity. For that, it is necessary for a programmer to know the memory
management.
If at all any modification is done the some segments, the starting addresses of immediate next
segments may get changed, the programmer has to take care of this issue and he needs to update
the corresponding starting addresses on any modification in the source.
Algorithm for absolute Loader
Input: Object codes and starting address of program segments.
Output: An executable code for corresponding source program. This executable code is to be
placed in the main memory
Method:
Begin
For each program segment
do Begin
Read the first line from object module to
obtain information about memory location. The
starting address say S in corresponding object

module is the memory location where executale


code is to be placed.
Hence
Memory_location = S
Line counter = 1; as it is first line While (!
end of file)
For the curent object code
do Begin
1. Read next line
2. Write line into location S
3. S = S + 1
4. Line counter Line counter + 1
Subroutine Linkage:
To understand the concept of subroutine linkages, first consider the following scenario:
"In Program A a call to subroutine B is made. The subroutine B is not written in the program
segment of A, rather B is defined in some another program segment C" Nothing is wrong in it.
But from assembler's point of view while generating the code for B, as B is not defined in the
segment A, the assembler can not find the value of this symbolic reference and hence it will
declare it as an error. To overcome problem, there should be some mechanism by which the
assembler should be explicitly informed that segment B is really defined in some other segment
C. Therefore whenever segment B is used in segment A and if at all B is defined in C, then B
must -be declared as an external routine in A. To declare such subroutine as external, we can use
the assembler directive EXT. Thus the statement such as EXT B should be added at the
beginning of the segment A. This actually helps to inform assembler that B is defined somewhere
else. Similarly, if one subroutine or a variable is defined in the current segment and can be
referred by other segments then those should be declared by using pseudo-ops INT. Thereby the
assembler could inform loader that these are the subroutines or variables used by
other segments. This overall process of establishing the relations between the subroutines can be
conceptually called a_ subroutine linkage.
For example
MAIN START
EXT B
.
.
.
CALL B
.
.
END
B START
.
.
RET

END
At the beginning of the MAIN the subroutine B is declared as external. When a call to subroutine
B is made, before making the unconditional jump, the current content of the program counter
should be stored in the system stack maintained internally. Similarly while returning from the
subroutine B (at RET) the pop is performed to restore the program counter of caller routine with
the address of next instruction to be executed.
Concept of relocations:
Relocation is the process of updating the addresses used in the address sensitive instructions of a
program. It is necessary that such a modification should help to execute the program from
designated area of the memory. The assembler generates the object code. This object code gets
executed after loading at storage locations. The addresses of such object code will get specified
only after the assembly process is over. Therefore, after loading, address of object code = Mere
address of object code + relocation constant. There are two types of addresses being generated:
Absolute address and,relative address. The absolute address can be directly used to map the
object code in the main memory. Whereas the relative address is onlyafter the addition of
relocation constant to the object code address. Thiskind of adjustment needs to be done in case of
relative address beforeactual execution of the code. The typical example of relative reference is :
addresses of the symbols defined in the Label field, addresses of the datawhich is defined by the
assembler directive, literals, redefinable symbols.Similarly, the typical example of absolute
address is the constants whichare generated by assembler are absolute.The assembler calculates
which addresses are absolute and whichaddresses are relative during the assembly process.
During the assemblyprocess the assembler calculates the address with the help of simple
expressions.
For example:
LOADA(X)+5
The expression A(X) means the address of variable X. The meaning ofthe above instruction is
that loading of the contents of memory locationwhich is 5 more than the address of variable X.
Suppose if the address ofX is 50 then by above command we try to get the memory location
50+5=55. Therefore as the address of variable X is relative A(X) + 5 isalso relative. To calculate
the relative addresses the simple expressionsare allowed. It is expected that the expression should
possess at the mostaddition and multiplication operations. A simple exercise can be carriedout to
determine whether the given address is absolute or relative. In theexpression if the address is
absolute then put 0 over there and if address isrelative then put lover there. The expression then
gets transformed to sumof O's and l's. If the resultant value of the expression is 0 then
expressionis absolute. And if the resultant value of the expression is 1 then theexpression is
relative. If the resultant is other than 0 or 1then theexpression is illegal. For example:

In the above expression the A, Band C are the variable names. Theassembler is to consider the
relocation attribute and adjust the objectcode by relocation constant. Assembler is then
responsible to convey theinformation loading of object code to the loader. Let us now see how
assembler generates code using relocation information.
Direct Linking Loaders
The direct linking loader is the most common type of loader. This type ofloader is a relocatable
loader. The loader can not have the direct access tothe source code. And to place the object code
in the memory there aretwo situations: either the address of the object code could be absolute
which then can be directly placed at the specified location or the addresscan be relative. If at all
the address is relative then it is the assembler whoinforms 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 currentsegment but can be used in the
current segment.
3) The list of all the symbols which are defined in the current segment butcan 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 USEtable. 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 bereferred by the other
segments are stored in a data structure calledDEFINITION table. The definition table holds the
information such assymbol, address.
Direct linking:
As we have seen in overlay structure certain selectivesubroutines can be resident in the memory.
That means it is not necessaryto resident all the subroutines in the memory for all the time. Only
necessary routines can be present in the main memory and duringexecution the required
subroutines can be loaded in the memory. Thisprocess of postponing linking and loading of
external reference untilexecution is called dynamic linking. For example suppose the subroutine
main calls A,B,C,D then it is not desirable to load A,B,C and D alongwith the main in the
memory. Whether A, B, C or D is called by the mainor not will be known only at the time of
execution. Hence keeping theseroutines already before is really not needed. As the subroutines
getexecuted when the program runs. Also the linking of all the subroutineshas to be performed.
And the code of all the subroutines remains residentin the main memory. As a result of all this is
that memory gets occupiedunnecessarily. Typically 'error routines' are such routines which can
beinvoked rarely. Then one can postpone the loading of these routinesduring the execution. If
linking and loading of such rarely invokedexternal references could be postponed until the
execution time when itwas found to be absolutely necessary, then it increases the efficiency of

overhead of the loader. In dynamic linking, the binder first prepares aload module in which along
with program code the allocation andrelocation information is stored. The loader simply loads
the mainmodule in the main memory. If any external reference to a subroutine
comes, then the execution is suspended for a while, the loader brings therequired subroutine in
the main memory and then the execution process isresumed. Thus dynamic linking both the
loading and linking is donedynamically.
Advantages
1. The overhead on the loader is reduced. The required subroutine will be
load in the main memory only at the time of execution.
2. The system can be dynamically reconfigured.
Disadvantages The linking and loading need to be postponed until the
execution. During the execution if at all any subroutine is needed then the
process of execution needs to be suspended until the required subroutine
gets loaded in the main memory.
Bootstrap Loader:
As we turn on the computer there is nothingmeaningful in the main memory (RAM). A small
program is written andstored in the ROM. This program initially loads the operating system
from secondary storage to main memory. The operating system then takesthe overall control.
This program which is responsible for booting up thesystem is called bootstrap loader. This is the
program which must beexecuted first when the system is first powered on. If the program
startsfrom the location x then to execute this program the program counter ofthis machine should
be loaded with the value x. Thus the task of settingthe initial value of the program counter is to
be done by machinehardware. The bootstrap loader is a very small program which is to befitted
in the ROM. The task of bootstrap loader is to load the necessaryportion of the operating system
in the main memory .The initial addressat which the bootstrap loader is to be loaded is generally
the lowest (maybe at 0th location) or the highest location. .
Concept of Linking:
As we have discussed earlier, the execution ofprogram can be done with the help of following
steps
1. Translation of the program(done by assembler or compiler)
2. Linking of the program with all other programs which are needed forexecution. This also
involves preparation of a program called loadmodule.
3. Loading of the load module prepared by linker to some specifiedmemory location.
The output of translator is a program called object module. The linkerprocesses these object
modules binds with necessary library routines andprepares a ready to execute program. Such a
program is called binaryprogram. The "binary program also contains some necessary
informationabout allocation and relocation. The loader then load s this program into
memory for execution purpose.
Various tasks of linker are 1. Prepare a single load module and adjust all the addresses andsubroutine references with
respect to the offset location.

2. To prepare a load module concatenate all the object modules and adjustall the operand address
references as well as external references to theoffset location.
3. At correct locations in the load module, copy the binary machineinstructions and constant data
in order to prepare ready to executemodule.
The linking process is performed in two passes. Two passes are necessarybecause the linker may
encounter a forward reference before knowing itsaddress. So it is necessary to scan all the
DEFINITION and USE table atleast once. Linker then builds the Global symbol table with the
help ofUSE and DEFINITION table. In Global symbol table name of eachexternally referenced
symbol is included along with its address relative tobeginning of the load module. And during
pass 2, the addresses ofexternal references are replaced by obtaining the addresses from global
symbol table.

UNIT 4
Editors:
An interactive editor is a computer program that allows a user to create and revise a
target document.
The term document includes objects such as computer programs, texts, equations,
tables, diagrams, line
arts and photographs-anything that one might find on a printed page.
Text editor is one in which the primary elements being edited are character strings
of the target text.

The document editing process is an interactive user-computer dialogue designed to


accomplish four
tasks:
1) Select the part of the target document to be viewed and manipulated
2) Determine how to format this view on-line and how to display it.
3) Specify and execute operations that modify the target document.
4) Update the view appropriately.
Traveling Selection of the part of the document to be viewed and edited. It
involves first traveling
through the document to locate the area of interest such as next
screenful,bottom, and find
pattern Traveling specifies where the area of interest is;
Filtering: The selection of what is to be viewed and manipulated is controlled by
filtering.
Filtering extracts the relevant subset of the target document at the point of interest,
such as next
screenful of text or next statement.
Formatting: Formatting then determines how the result of filtering will be seen as
a visible
representation (the view) on a display screen or other device.
Editing: In the actual editing phase, the target document is created or altered with
a set of operations
such as insert, delete, replace, move or copy. Manuscript oriented editors operate
on elements such as
single characters, words, lines, sentences, and paragraphs; Program-oriented
editors operates on
elements such as identifiers, key words and statements

For any computing environment interactive text editors has an important part.
Various types of editors are:

Text editor should be the primary interface to the computer for all types 0 knowledge workers.
Overview of the editing process'
An interactive editor is a computer program that allows a user to create anrevise a target
document.
The document means an object such as computer programs, text, equations tables, diagrams,
photographs etc.
The document editing process in an interactive user computer dialogue designed to accomplish
four tasks:
1)Select the part of the target document to be viewed & manipulated.
2)Determine how to format this view online and how to display it.
3)Specify and execute operations that modify the target document.
4)Updatethe view appropriately.
Selection of the part of the document to be viewed and edited involves first travelling through
the document to locate the area of interest.
Travelling implies movement of the editing context to a new position within the text. The
selection of what is to be viewed and manipulated that is controlled by filtering.
Filtering extracts the relevant subset of the target document at the point of interest, such as the
next screenful of text or the next statement.
Formatting determines how the result of the filtering will be seen as a visible representation on
a display screen or other devices.
In the actual editing phase, the target document is created or altered with a set of operations
such as insert, delete, replace, move and copy

.Design of an Editor:
The fundamental functions in editing are travelling, editing, viewing and display.
Travelling implies movement of the editing context to a new position within the text.
Viewing implies formatting the text in a manner desired by the user.
A simple text editor' may choose to combine the viewing and display functions.
Figure below shows the simple editor.

In editing document, the start of the area to be edited is determined by the current editing
pointer maintained by the editing component.
The travelling component of the editor actually performs the setting of the current editing and
viewing pointers. It also determines the point at which the viewing and editing filters.
The current editing pointer can be set or reset explicitly by the user with travelling commands,
such as next paragraph and next screen.
When a user issue an editing command the editing component invokes the editing filter.
Editing component filters the document to generate a new editing buffer based on the current
editing pointer as well as on the editing filter parameters.
Filtering may simply consists of the selection of contiguous characters beginning at the current
point.
Current viewing pointer determined the start of the area to be viewed for viewing a document.
Current viewing pointer can be set or reset explicitly by the user with a travelling command or
implicitly by the user with a travelling command or implicitly by the system as a result of the
previous editing operation.
For a given position of the editing context, the editing and viewing filters operate on the
internal form of text to prepare the forms suitable for editing viewing.

Figure below shows the block diagram of typical editor structure.

When the cursor position changes, the filters operate on a new portion of text to update the
contents of the buffers.
As editing is performed, the editing filter reflects the changes into the internal form and update
the content of the viewing buffer.
The editing and viewing buffers are independent in some cases. They are identical sometime as
shown is Figure below:

(Editing and viewing buffer)


The editing and viewing buffer can also partially overlap or one may be completely contained
in the other.
For example, the user might specify a search to the end of the document, starting at a character
position in the middle of the screen.

In the above example, an editing filter creates an editing buffer that contains the document from
the selected character of the end of the document.
The viewing buffer contains the part of the document that is visible on the screen. Only the last
part of which is in the editing buffer.
Screen Editors:
Screen editor uses the whatyou see is what you get principle in editor design.
Aeditor displays a screenful of text at a time. The user can move the cursor over the screen,
position it at the point where user desires to perform some editing and proceed with the editing
directly.
Document
Display
Window
Editing buffer
Viewing buffer
8
The user has full control over the entire terminal. For example over an type exiting string which
user wishes to replace. User can bring the cursor over a character to be deleted and press a delete
key.
It is possible to see the effect of an edit operation on the screen.
Line Editor:
Line editor is one of the simplest type of editor which uses a buffer to store information:
It operates in command mode. User give the command to the editor for any operation. Editor
will respond this command.
Buffer is in the main memory. That is set aside to store the information which is entered from
the keyboard.
Merits
1)Simple for read and write.
2)Simplein design and implementation
3)Command and responses are interleaved.
Demerits
1)Not user friendly
2)Contextof the text is not displayed.
3)Onlysingle line is used for editing.
Stream Editor:
A stream editor views the entire text as a stream of characters. This permits edit operations to
cross line boundaries.
Stream editor typically support character line and context orient commands.
In stream editor, the current editing context indicated by the position of text pointer. This
pointer can be manipulated using positioning.
Stream editor maintain multiple representations.
Word Processors:
It is document editors with additional features. It produce well formatted output.
Features of text
a)Merging of text
b)Searchingand replacement of word
c)Moving sections of text

9
User Interface:
User interface simplify the interaction of a user with an application.
UI consists of two components: Dialog manager and presentation manager.
Dialog manager manage the conversation between the user and the application.
Presentation manager displays the data produced by the application in an appropriate manner
on the user display.
Figure below show user interface.

Dialog manager is also responsible for error messages and online help function, and for
organizing changes in the visual context of the user.
User Interface Management System (UIMS) automates the generation of user
Interface.
UIMS takes specification of the presentation and dialog semantics to produce the presentation
and dialog managers of the UI.
Application code
Dialog manager
Presentation manager
Graphics package
10
Commands dialogs Command dialogues are used to issue commands. Command dialogues
are implemented in following ways.
a)Command language.
b)Command menu.
c)Direct manipulation.
User interface is concerned with the input devices output devices and interaction language of
the system.
Input devices are used to enter elements of the text being edited, to enter commands, and to
designate editable elements. These devices as used with editors can be divided into the
categories:
a)Text devices

b)Button devices
c)Locator devices
Text or string devices are typically typewritter like keyboards on which a user presses and
releases keys, sending a unique code for each key.
Button or choice devices generates an interrupt or set a system flag. Such devices typically
include a set of special function keys on an alphanumeric keyboard.
Locator devices are two dimensional analog to digital converters that position a cursor symbol
on the screen by observing the user's movement the device. The most common such devices for
editing applications are the mouse and the data tablet.
Text devices with arrow keys can be used to simulate locator devices. Each these keys shows an
arowthat point up, down, left or right.
The interaction language of a text editor is generally one of several common types.
a)Typing oriented
b)Text command oriented
The user communicates with the editor by typing text strings both for command names and for
operands. These strings are sent to the editor and are usually echoed to the output device.
Typed specification often requires the user to remember the exact form of all commands, or at
least their abbreviations. Function key command specification is typically coupled with cursor
key movement for specifying operands, which eliminates much typing.
Typing oriented systems require familiarity with the system and language, as well as some
expertise in typing. Function key oriented systems often have either too few keys, requiring
multiple keystroke commands, or have too many unique keys, which result in an
unwidelykeyboard.
The menu oriented user interface solve the problem of typing oriented anfunction key oriented
systems. A menu is a multiple choice set of text strings or icons, which are graphic symbols that
represents objects or operations. The user can perform actions by selecting items from the menu.
Problem with a menu oriented system can arise when there are many possible actions and
several choices are required to complete an action.
Debugging Function and Capabilities:
Debugging system should provide functions such as tracing and traceback.
Tracing can be used to track the flow of execution logic and data modifications. It can also be
based on conditional expressions.
Traceback can show the path by which the current statement was reached. It can also show
which statements have modified a given variable or parameter.
Debugging system have a good program display capabilities. It must be possible to display the
program being debugged, complete with statement numbers.
The system should save all the debugging specifications across such a recompilation, so the
user does not need to reissue all of these debugging commands.
Debugging system must be sensitive to the specific languge being debugged so that procedural,
arithmetic and conditional logic can be coded in the syntax of that language.
The debugger should be able to switch its context when a program written in one language calls
a program written in a different language.
. A debugging system must be able to deal with optimized code. Application code used in
production environments is usually optimized. Debug Monitors:
Dynamic debugging facility is provided by the debug monitors. It includes following activities.

1) Setting breakpoints in the program.


12
2) Initiating a debug conversation when control reaches a breakpoint.
3)Displayingvalues of variables.
4)Assigning new values to variables.
5)Testing user defined assertions and predicates involving program variables.
When the user a commands to set a breakpoint the debug monitor instruments the program to
introduce a sensing instruction before the start of the statement at breakpoint.
The debug monitor function can be easily implemented in an interpreter.
When a user gives a command to set a breakpoint at statement 150, Thedebug monitor
instruments the program to introduce the instruction.
<SI-instrn><code>in place of the no-op instructions preceding no-op 150.
The debug monitors requires two kind of information regarding the user program.
a) Starting address of program statements in the complied code.
b) Program variables name and address.
Dynamic debugging of a program Following sequence of step involved .in dynamic
debugging of a program.
1)Theuser compiles the program under the debug option. The compiler produces two file i.e.
a)Complied code file
b)Debuginformation file
2)Theuser activates the debug monitor and indicates the name of program to be debugged.
Debug monitor opens the corresponding two files.
2)Userindicates the debug requirements i.e. a list of breakpoints and action to performed at
breakpoints. Debug monitor builds a debug table. This table _contains, <statement number,
debug action.>'
3)The instrumented program gets the control and executes up to a breakpoint.
2)When<SCinstrn> is excuted, software interrupt is generated and control is given to the debug
monitor. Debug monitor construct the debug table and perform the debug actions associated with
it.
13
Control now returns to the u program.
3)Steps (4) and (5) are repeated until the end of the debug session.
Relationship with other parts of the system:
Important requirement for an interactive debugger is that it always be available. It must appear
to be a part of the run-time environment and a integral part of the system. When an error is
discovered, immediate debugging must be possible because it may be difficult or impossible to
reproduce the program failure in some other environment or at some other time. So the debugger
must communicate and cooperate with other operating system components such as interactive
subsystems.
Debugging is even more important at production time than it is at application development
time. When an application fails during a production run, work dependent on that application
stops. Since the production environment is often quite different from, the test environment, many
program failure cannot be repeated outside the production environment.
The debugger must coordinate its activities with those of existing and future language
compilers and interpreters. It is assumed that debugging facilities in existing languages will
continue to exist and be maintained.

User Interface Crteria:


Most common complaint about debugging products is that they are something new to learn.
This problem is solved by using simple organization and familiar in its language. The facilities of
the debugging system should be organized into a few basic categories of function, which should
closely reflect common user tasks. This type of simple organization contributes greatelyto ease
of training and ease of use.
The user interaction should make use of full screen displays and windowing system as much as
possible. The advantage of this type is that a great deal of information can be displayed and
changed easily and quickly. with menus and full screen editors, the, user has far less information
to enter and remember.
If the tasks a user needs to perform are reflected in the organization of menus, then the system
will feel very natural to use. Menu should have titles that identify the task they help perform.
Directions should precede any choices available to the user.
14
Use of full screen displays and techniques such as menu is highly desirable. A debugging
system should also support interactive users when a full screen terminal device is not present. It
also provide complete functional equivalence between commands and menus.
The command language should have a clear, logical simple syntax. It should also be as similar
to the programming language as possible. Use simple command and instead of compound
command. Parameters are as few as possible. Parameters should automatically be checked for
errors in such attributes as type and range of values. Defaults should be provided for most
parameters.
Command formats should be as flexible as possible. The command language should minimize
the use of such punctuation as parentheses, slashes, quotation marks and other special characters.
Any good interactive system should have an online HELP facility.

You might also like