System Software: Macro Processors Overview
System Software: Macro Processors Overview
MODULE V
Macro Preprocessor
o Macro Instruction Definition and Expansion.
o One pass Macro processor Algorithm and data structures
o Machine Independent Macro Processor Features
Concatenation of Macro Parameters
Generation of unique labels
Conditional Macro Expansion
Keyword Macro Parameters
o Macro processor design options
Recursive Macro Expansion
General-Purpose Macro Processors
Macro Processing within Language Translators
Text Editors
o Overview of Editing
o User Interface
o Editor Structure.
Debuggers
o Debugging Functions and Capabilities
o Relationship with other parts of the system
o Debugging Methods
By Induction
Deduction
Backtracking
Device drivers
o Anatomy of a device driver
o Character and block device drivers
o General design of device drivers
Macro Preprocessor
o Function: Substitution of one group of characters or lines for another.
o It does not perform analysis of the text it handles.
1 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
o Macro Definition
Assembler directives used in macro definition
MACRO: specifies the be n ginning of a macro definition
MEND: specifies the end of a macro definition
Syntax of Macro:
Macro_Name MACRO parameters
-----
----- Body
-----
MEND
Macro Prototype statement: The first line of the macro definition
is called macro prototype statement.
2 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
The symbol in the label field of the prototype statement is the macro
name.
Parameters are begins with „&‟
Body: The statements that will be generated as the expansion of the
macro
o Macro Expansion
Each macro invocation statement will be expanded into the statements
that form the body of the macro.
Arguments from the macro invocation are substituted for the parameters
in the macro prototype (according to their positions).
In the definition of macro: parameter
In the macro invocation: argument
Comment lines within the macro body will be deleted.
Macro invocation statement itself has been included as a comment line
The label on the macro invocation statement has been retained as a label
on the first statement generated in the macro expansion
Example:
Source Code Expanded Code
PGM START 0 PGM START 0
ABC MACRO &A,&B . ABC P,Q //Comment line
STA &A STA P
STB &B STB Q
MEND .ABC R,S //Comment line
ABC P,Q STA R
ABC R,S STB S
END END
3 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
4 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
5 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
o Example:
The following program shows an example of a SIC/XE program using
macro Instructions.
This program defines two macros:
RDBUFF: Similar to RDREC subroutine
WRDUFF: Similar to WRREC subroutine
Line 10 and 100 are the beginning of first and second macro definition.
The instruction on line 55 is JEQ *-3
Means jump to 3 location back.
This type of PC relative addressing mode is used to avoid labels in
the macro body.
The MAIN program contains 3 macro calls on line 190, 210 and 220.
Each macro invocation statement has been expanded into the statements
that form the body of the macro, with the arguments from macro
invocation substituted for the parameters in macro prototype.
The arguments and parameters are associated with one another
according to their positions.
The macro definition has been deleted since they have been no longer
needed after macros are expanded
TYPES OF MACROS
o Simple Macro
o Parameterized Macro
o Nested Macro
o Recursive Macro
6 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Simple Macro
o A macro without argument is called simple macro.
Source Code Expanded Code
ABC MACRO . ABC
STA A STA A
STB B STB B
MEND . ABC
ABC STA A
ABC STB B
Parameterized Macro
o A macro with argument is called parameterized macro.
o Two types of Parameterized Macros
Positional Parameters
Keyword Parameters
o Positional Parameters
The programmer must specify the arguments in proper order.
Parameters and arguments are associated according to their position
in the macro prototype and invocation.
When the macro is called, the parameters will be replaced within the
macro body by the value specified.
If an argument is to be omitted, a null argument should be used to
maintain the order in the macro invocation statement.
Source Code Expanded Code
ABC MACRO &A,&B . ABC P,Q
STA &A STA P
STB &B STB Q
MEND . ABC Q,P
ABC P,Q STA Q
ABC Q,P STB P
o Keyword Parameters
Arguments may appear in any order.
Each argument value is written with a keyword that names the
corresponding parameter. Each parameter name is followed by =
Null arguments no longer need to be used.
7 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Nested Macro
o A macro body may contain another macro definition
o Example: Here the macro SWAP defines another macro STORE inside
it.
SWAP MACRO &X,&Y //Outer Macro Definition
LDA &X
LDX &Y
STORE MACRO &X,&Y //Inner Macro Definition
STA &Y
STX &X
MEND
MEND
o The expansion of nested macro calls follows the last-in-first-out
rule(LIFO).
o The expansion of latest macro call is completed first.
Recursive Macros
o A macro definition contains another macro call. This call may be the
same macro or a different macro.
ABC MACRO &A,&B
--------
--------
PQR X,Y
--------
--------
MEND
PQR MACRO &P,&Q
--------
--------
MEND
8 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
9 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
PROCESSLINE()
{ Search NAMETAB for OPCODE
If found then EXPAND()
Else if OPCODE=’MACRO’ then DEFINE()
Else Write source line to expanded file
}
DEFINE()
{ Enter macro name into NAMTAB
Enter macro prototype into DEFTAB
LEVEL = 1
While LEVEL > 0
{ GETLINE()
If this is not a comment line
{ Substitute positional notation for parameters
10 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
EXPAND()
{ EXPANDING = TRUE
Get prototype statement from DEFTAB
Set up arguments from macro invocation in ARGTAB
Write macro invocation to expanded file as comment
While not end of macro definition
{ GETLINE()
PROCESSLINE()
}
EXPANDING = FALSE
}
GETLINE()
{ If EXPANDING==TRUE
{
Get next line of macro definition from DEFTAB
Substitute arguments from ARGTAB for positional notation
}
Else Read next line from input file
}
o The procedure DEFINE, which is called when the beginning of a
macro definition is recognized, makes the appropriate entries in
DEFTAB and NAMTAB.
o When a macro definition is being entered into DEFTAB, the
normal approach is to continue until an MEND directive is
reached.
o This would not work for nested macro definition because the
first MEND encountered in the inner macro will terminate the
whole macro definition process.
o To solve this problem, a counter LEVEL is used to keep track of
the level of macro definitions.
Increase LEVEL by 1 each time a MACRO directive is read.
Decrease LEVEL by 1 each time a MEND directive is read.
o A MEND terminates the whole macro definition process when
LEVEL reaches 0.
11 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
12 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Example:
IF-ELSE-ENDIF structure
The macro processor must maintain a symbol table
This table contains the values of all macro-time variables used
Entries in this table are made or modified when SET statements are
processed.
This table is used to look up the current value of a macro-time
variable whenever it is required.
When an IF statement is encountered during the expansion of a
macro, the specified Boolean expression is evaluated. If value is
o TRUE
The macro processor continues to process lines from
DEFTAB until it encounters the next ELSE or ENDIF
statement.
If ELSE is encountered, then skips to ENDIF
14 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
o FALSE
The macro processor skips ahead in DEFTAB until it finds
the next ELSE or ENDIF statement.
Ex:
MACRO &COND
………….
IF (&COND NE „‟)
PART I
ELSE
PART II
END IF
………….
ENDM
o Part I is expanded if condition part is true, otherwise part II is
expanded
o Compare operator: NE, EQ, LE, GT
IF, ELSE and ENDIF statements will not be in the expanded code.
15 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Example:
Macro Definition:
Macro Call:
Expanded Code:
16 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Macro Call:
Expanded Code:
Macro Call:
Expanded Code:
17 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Example:
Macro Definition:
Macro Call:
18 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Expanded Code:
19 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Example:
Macro Definition:
The following macro definition contains 5 parameters. Three of them
(&INDEV,&EOR,&,MAXLTH) having default value.
20 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Macro Call:
Expanded Code
21 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
23 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
24 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Disadvantages
Large number of details must be dealt with in a real programming
language
In a typical programming language, there are several situations in
which normal macro parameter substitution should not occur
Each programming language has its own methods for identifying
comments
o Some languages use special characters to mark the start and end
of a comment.
o Some languages use a special character to mark only the start of
a comment. The comment is automatically terminated at the end
of the source line.
o Some languages use a special symbol to flag an entire line as a
comment.
o In most assembly languages, an characters on a line following
the end of the instruction operand field are automatically taken
as comments
Each programming languages having their own facilities for
grouping together terms, expressions, or statements
o Some languages use keywords such as begin and end for
grouping statements.
o Others use special characters such as { and } for grouping
statements.
A more general problem involves the tokens of the programming
language like identifiers, constants, operators, and keywords
o Languages differ their restrictions on the length of identifiers
and the rules for the formation of constants.
o Some languages support multiple character operators. Eg: **
Another potential problem with general purpose macro processors
involves the syntax used for macro definitions and macro invocation
statements. With most special purpose macro processors, macro
invocations are very similar in form to statements in the source
programming language.
25 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
27 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Text Editors
o Text editors are software programs that enable the user to create and edit
text files.
o Example: Notepad, Wordpad, MS Word etc.
o A document may include objects such as Computer programs, Equations,
Tables, Diagrams, Line art, Photographs etc.
Editing Steps:
TRAVELING
o It involves traveling through the document to locate the area of
interest such as next screenful , bottom and find pattern.
FILTERING
o Selection of what is to be viewed and manipulated is controlled
by filtering.
o Filtering extracts the relevant subset of the target document at
the point of interest such as next screenful of text or next
statement.
FORMATING
o Determines how the result of filtering will be seen on a display
screen.
EDITING PHASE
o Editing phase involves – insert, delete, replace, move, copy, cut,
paste, etc...
28 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Input Devices
o Input devices are used to enter elements of the text being edited,
to enter commands, and designate editable elements.
o Input devices are categorized as:
Text devices/String Devices
These are typically typewriter like keyboards on which
user presses and releases keys, sending unique code for
each key.
Virtually all computer keyboards are of QWERTY type.
Button devices/Choice Devices
Special function keys on alpha numeric keyboard
It generates an interrupt or set a system flag, usually
causing an invocation of an associated application
program action.
Locator devices
These are two dimensional analog to digital converters
that position a cursor symbol on the screen by observing
the users movement of the device.
Ex: Mouse , Joysticks, Touch screens, Data tablets etc
Voice input device
It translates spoken words to their textual equivalents.
29 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Output Devices
o Output devices let the user view the elements being edited and
the result of the editing operations.
o The first output devices were teletypewriters, that generates
output on paper
o Next is Cathode ray tube (CRT), which uses CRT screen for
display.
o The modern professional workstations are based on personal
computers with high resolution displays.
Interaction Languages
o The interaction language could be,
Typing oriented/ Text command oriented
Oldest editors are typing oriented
The user communicates with the editor by typing text
strings.
These strings are sent to the editor and are usually
echoed to the output device.
The users should remember the exact form of all
commands.
In order to avoid that, we can use function key
interfaces.
Each command is associated with marked key on
keyboard .This eliminate much typing
o Eg: Insert Key, Shift Key, Control key etc.
Disadvantage: Have too many unique keys which will
result in a unwieldly keyboard.
30 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Editing Component
Editing operations are always specified by the user.
The editing component is a collection of modules dealing with the
editing tasks.
The start of the area to be edited is determined by the current
editing pointer maintained by the editing component.
The current editing pointer can be set or reset explicitly by the user
with the travelling commands or implicitly by the system as a side
effect of previous editing operation.
31 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Viewing Component
It is a collection of modules responsible for determining the next
view.
In viewing a document, the start of the area to be viewed is
determined by the current viewing pointer.
The pointer can be set or reset explicitly by the user with a traveling
command or implicitly by the system as a result of the previous
editing operation.
The pointer is maintained by the viewing component.
When the display needs to be updated, the viewing component
invokes the viewing filter.
32 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Traveling Component
It performs the setting of the current editing and viewing pointers,
and thus determines the point at which the viewing and editing
begins.
Display Component
Display operations are always specified implicitly by the other three
categories of operations : editing, traveling and viewing.
It takes the idealized view from the viewing component and maps it
to a physical output device in the most efficient manner
It produces a display by mapping the viewing buffer to a rectangular
subset of the screen, usually called a screen.
Debugger
o A debugger is a computer program that is used to test and debug other
programs.
o Debugging is the activity of locating and correcting errors.
o It can start once a failure has been detected.
o An interactive debugging system provides programmers with facilities that
aid in testing and debugging a program.
o Debugging is a two step process that begins when you find an error as a
result of a successful test case
Determine the exact nature and location of the suspected error within the
program.
Fixing the error.
o Difference between Testing and Debugging
Testing: process of executing a program with the aim of finding errors or
bugs.
Debugging: correcting these errors found during testing is debugging.
o Types of bugs:
Compile time: Usually caught with compiler
Eg: Syntax, Spelling, type mismatch etc.
Design time:
Flawed algorithm
33 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
35 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
o Debugging Methods
Debugging By Induction(Reasoning strategy/thoughtful strategy)
Many errors can be found by using a disciplined thought process
without the debugger ever going near the computer.
One such thought process is induction which can figure out solution
to a problem.
Here we start with our own experience and then generalize a rule
This strategy assumes that once the symptoms of the errors are
identified, and the relationships between them are established, the
errors can be easily detected by just looking at the symptoms and the
relationships.
37 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Debugging By Deduction
The process of deduction proceeds from some general theories or
premises, using the processes of elimination and refinement, to
arrive at a conclusion.
38 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
o Hence the next step is to use the available clues to refine the
theory.
Prove/Disprove the hypothesis
o Prove the reasonableness of the hypothesis
Debugging By Backtracking
Backtrack the incorrect result through the logic of the program until
you find the point where the logic went off track. That means, find
the point where the program gives incorrect result.
For large programs, such analysis at the statement level would be
too tedious to perform. What we seek is to first narrow the user‟s
focus to a small region of the program that is likely to contain an
error, and then do statement level analysis within this region.
The program is viewed as a sequence of logical blocks instead of
individual statements.
One need only to think backwards at the program block level instead
of the statement level
To perform such backward analysis using conventional interactive
debuggers, one would first set a breakpoint just before the last
logical block. If the program state is found to be correct at this point,
it would imply that the error occurred within the last block.
Otherwise another breakpoint would be set before the second-last
block, and the program reexecuted. If the program state is found to
be correct at that point, then we may conclude that the error resides
within that second-last block. Otherwise this process of setting
breakpoints in backward order and reexecuting the program
continues until the erroneous block is discovered.
If N is the number of blocks in the program, then clearly this method
of setting breakpoints successively in backwards order and
reexecuting the program every time leads to an O(N2) cost for
execution and require only O(N) block executions.
Device Drivers
o A Device Driver is glue between an OS and its I/O devices.
o Device drivers communicate directly with devices. They act as translators
converting generic requests received from the operating system into
commands that specific peripheral controllers can under-stand.
o Relationship between an application software, OS and device driver is
illustrated below.
39 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
o Device driver simplifies the design of OS. Without the device drivers the
operating system would be responsible for talking directly to the hardware.
This would require the OS designer to include support for all the devices
that the users might want to connect to the computer. It would also mean
adding support to a new device would require modifying the OS. By
separating device driver's functions from OS, the designer can concentrate
on the issues related to the operation of the system as a whole. Thus device
40 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
driver designer does not have to worry about the general issues related to
I/O management which is handled by the OS. The device driver writer can
connect any I/O device to the system without having to modify the OS.
Device drivers thus provide the OS with a standard interface to non-
standard I/O devices.
o Device Characteristics
Identifier: A universally unique identifier that is intrinsic to the device.
Operational State: Indicates whether the device is mounted or
unmounted.
LUN: Logical Unit Number (LUN) within the SCSI target. The LUN
number is provided by the storage system. If a target has only one LUN,
the LUN number is always zero (0).
Type: Type of device, for example, disk or CD-ROM.
Drive Type: Information about whether the device is a solid-state drive
(SSD) or a regular non-SSD hard drive.
Capacity: Total capacity of the storage device.
41 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Block Drivers
It communicates with OS through a collection of fixed-sized buffers.
Example: Disk drives
The OS manages a cache of these buffers and attempts to satisfy
user requests for data by accessing buffers in the cache. The driver is
invoked only when the requested data is not in the cache or when
buffers in the cache have been changed and must be written out.
Character Drivers
It can handle I/O requests of arbitrary size and can be used to
support almost any type of device. Mostly used devices are Printers.
Usually character drivers are used for devices that either deal with
data a byte at a time or work best with data in chunks smaller or
larger than the fixed sized buffers used by block drivers (eg tape
drives). The only relevant difference between a char device and a
regular file is that you can always move back and forth in the regular
file, whereas most char devices are just data channels, which you
can only access sequentially.
42 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
Terminal Drivers
Same as character drivers but specialized to deal with
communication terminals that connect users to OS. Terminal drivers
are not only responsible for shipping data to and from user terminals
but also for handling line editing, tab expansion and many other
terminal functions that are part of the standard UNIX terminal
interface. Because of this additional processing that terminal drivers
must perform it is useful to consider terminal drivers as a separate
type of driver.
43 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
6. Describe the data structures used in a one pass macro processor algorithm. Give
examples
7. What are the data structures required for a macroprocessor algorithm? Explain
the format of each
8. Give the algorithm for a one pass macro processor
9. Explain the working of One pass Macro Processor
[Link] the algorithm for one pass macro processor and explain the process,
showing when and how the different data structures are used
[Link] and explain the different design options available for macroprocessors
[Link] recursive macro expansion with example
45 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck
Module V System Software(CST 305)
[Link] is a Debugger?
[Link] notes on the debugging functions and capabilities of an interactive
debugging system
[Link] out the criteria that should be met by the user interface of an efficient
debugging system
[Link] the different debugging methods in detail
[Link] down the situations where debugging by induction, deduction and
backtracking are used, explaining each process
46 CS KTU LECTURES
Reference Book: System Software: An Introduction to System Programming, Leland L Beck