System Software Module
System Software Module
MACRO PROCESSOR
A Macro represents a commonly used group of statements in the source programming
language.
body
MEND
o Body: the statements that will be generated as the expansion of the macro.
[Type text]
5.1 Basic Macro Processor Functions:
Consider the example of an SIC/XE program using macro instructions. This program defines
and uses two macro instructions , RDBUFF and WRBUFF.
The functions and logic of RDBUFF macro are similar to RDREC subroutine.
[Type text]
Two new assembler directives (Macro and MEND) are used in macro definitions. The keyword
macro identifies the beginning of the macro definition. The symbol in the label field (RDBUFF)
is the name of the macro and entries in the operand field identify the parameters of the macro.
Each parameter begins with the character & which helps in the substitution of parameters
during macro expansion. Following the macro directive are the statements that make up the
body of the macro definition. These are the statements that will be generated as the expansion
of the macro. The MEND directive marks the end of the macro.
Macro invocation or call is written in the main program. In macro invocation the name of the
macro is followed by the arguments. Output of the macroprocessor is the expanded program.
[Type text]
Expanded Program
LDA &A
STA &B
MEND
EX1 N1,N2
N1 RESW 1
N2 RESW 1
END
[Type text]
Expanded program
. EX1 N1,N2
LDA N1
STA N2
N1 RESW 1
N2 RESW 1
Macro expansion
Macro definition statements have been deleted since they are no longer required after the macros
are expanded. Each macro invocation statement has been expanded into the statements that form
the body of the macro with the arguments from the macro invocation is substituted for the
parameters in the macro definition. Macro invocation statement is included as a comment line in
the expanded program.
After macroprocessing the expanded file can be used as input to the assembler.
Differences between macro and subroutine: The statements that form the expansion of a macro are
generated and (assembled ) each time the macro is invoked. Statements in a subroutine appear only
once, regardless of how many time the subroutine is called.
[Type text]
5.1.2 Macro Processor Algorithm and Data Structure:
It is easy to design a two pass macro processor in which all macro definitions are processed during
the first pass and all macro invocation statements are expanded during the second pass.
But such a two pass macro processor would not allow the body of one macro instruction to contain
definitions of other macros.
Here defining MACROS does not define RDBUFF and WRBUFF. These definitions are processed
only when an invocation of MACROS is expanded.
A one pass macro processor that can alternate between macro definition and macro expansion is
able to handle these type of macros.
There are 3 main data structures:-
The design of macro processor doesn’t depend on the architecture of the machine. We will be
studying some extended feature for this macro processor. These features are:
Most macro processor allows parameters to be concatenated with other character strings.
Suppose that a program contains a series of variables named by the symbols XA1, XA2,
XA3,…, another series of variables named XB1, XB2, XB3,…, etc. If similar processing
is to be performed on each series of labels, the programmer might put this as a macro
instruction.
The parameter to such a macro instruction could specify the series of variables to be
operated on (A, B, etc.). The macro processor would use this parameter to construct the
symbols required in the macro expansion (XA1, XB1, etc.).
If the macro definition contains &ID and &ID1 as parameters, the situation would be
unavoidably ambiguous.
Most of the macro processors deal with this problem by providing a special
concatenation operator. In the SIC macro language, this operator is the character .
Thus the statement LDA X&ID1 can be written as
LDA X&ID
it is not possible to use labels for the instructions in the macro definition, since every
expansion of macro would include the label repeatedly which is not allowed by the assembler.
We can use the technique of generating unique labels for every macro invocation and
expansion.
During macro expansion each $ will be replaced with $XX, where xx is a two- character
alphanumeric counter of the number of macro instructions expansion.
For example,
The following program shows the macro definition with labels to the instruction.
The following figure shows the macro invocation and expansion first time.
If the macro is invoked second time the labels may be expanded as $ABLOOP $ABEXIT.
Looping-WHILE
In the macro invocation statement there is a list(00,03,04) corresponding to the parameter &EOR.
Any one of these characters is to be considered as end of record.
The WHILE statement specifies that the following lines until the next ENDW are to be generated
repeatedly as long as the condition is true.
The testing of these condition and the looping are done while the macro is being expanded.The
conditions do not contain any runtime values.
%NITEMS is a macroprocessor function that returns as its value the number of members in an
argument list. Here it has the value 3. The value of &CTR is used as a subscript to select the
proper member of the list for each iteration of the loop. &EOR[&CTR] takes the values
00,03,04 .
Positional parameters are suitable for the macro invocation. But if the macro
invocation has large number of parameters, and if only few of the values need to be
used in a typical invocation, a different type of parameter specification is required.
Eg: Consider the macro GENER which has 10 parameters, but in a particular
invocation of a macro only the third and nineth parameters are to be specified. If
positional parameters are used the macro invocation will look like
GENER , , DIRECT, , , , , , 3,
But using keyword parameters this problem can be solved. We can write
GENER TYPE=DIRECT, CHANNEL=3
Keyword parameters
Each argument value is written with a keyword that names the corresponding
parameter.
Arguments may appear in any order.
Null arguments no longer need to be used.
It is easier to read and much less error-prone than the positional method.
We have seen an example of the definition of one macro instruction by another. But we have
not dealt with the invocation of one macro by another. The following example shows the
invocation of one macro by another macro.
Problem of Recursive Expansion
Previous macro processor design cannot handle such kind of recursive macro
invocation and expansion
o The procedure EXPAND would be called recursively, thus the invocation
arguments in the ARGTAB will be overwritten.
o The Boolean variable EXPANDING would be set to FALSE when the “inner”
macro expansion is finished, i.e., the macro process would forget that it had
been in the middle of expanding an “outer” macro.
The procedure EXPAND would be called when the macro was recognized. The arguments from
the macro invocation would be entered into ARGTAB as follows:
Parameter Value
1 BUFFER
2 LENGTH
3 F1
4 (unused)
- -
The Boolean variable EXPANDING would be set to TRUE, and expansion of the macro
invocation statement would begin. The processing would proceed normally until statement
invoking RDCHAR is processed. This time, ARGTAB would look like
Value
Parameter
1 F1
2 (Unused)
-- --
Solutions
o Write the macro processor in a programming language that allows recursive
calls, thus local variables will be retained.
o If you are writing in a language without recursion support, use a stack to take
care of pushing and popping local variables and return addresses.
Disadvantages- They must be specially designed and written to work with a particular
implementation of an assembler or compiler.. Cost of development is high.
An Interactive text editor has become an important part of almost any computing environment.
Text editor acts as a primary interface to the computer for all type of “knowledge workers” as
they compose, organize, study, and manipulate computer- based information.
A text editor allows you to edit a text file (create, modify etc…). For example the Interactive
text editors on Windows OS - Notepad, WordPad, Microsoft Word, and text editors on UNIX
OS - vi, emacs , jed, pico.
Normally, the common editing features associated with text editors are, Moving the cursor,
Deleting, Replacing, Pasting, Searching, Searching and replacing, Saving and loading, and,
Miscellaneous(e.g. quitting).
An interactive editor is a computer program that allows a user to create and revise a target
document. Document includes objects such as computer diagrams, text, equations tables,
diagrams, line art, and photographs. In text editors, character strings are the primary
elements of the target text.
Document-editing process in an interactive user-computer dialogue has 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
5.1.2User Interface:
Conceptual model of the editing system provides an easily understood abstraction of the
target document and its elements. For example, Line editors – simulated the world of the
key punch – 80 characters, single line or an integral number of lines, Screen editors –
Document is represented as a quarter-plane of text lines, unbounded both down and to the
right.
The user interface is concerned with, the input devices, the output devices and, the
interaction language. The input devices are used to enter elements of text being edited, to
enter commands. The output devices, lets the user view the elements being edited and the
results of the editing operations and, the interaction language provides communication
with the editor.
Input Devices are divided into three categories:
o text devices- are type writer like key boards on which a user presses and releases
keys sending a unique code for each key.
o button or choice devices- generate an interrupt causing an invocation of an
associated application program action. They include a set of function keys. Buttons
can be simulated in software.
o Locator devices – are two dimensional analog to digital converters that position a
cursor symbol on the screen by observing the user’s movement of the device. Eg:
mouse, data tablet. Returns the coordinates of the position of the device. Text
devices with arrow keys can be used as locator devices . Arrow shows left, right ,
up or down.
o Voice input devices- Translates spoken words to their textual equivalent.
Output Devices lets the user view the elements being edited and the results of the editing
operations. CRT terminals use hardware assistance for such features as moving the cursor ,
inserting and deleting characters and lines etc.
The interaction language is one of the common types.
o Typing or 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 echoed to the output device.This requires the user to
remember the commands.
o Function key oriented- In this each command is associated with a marked key on
the user’s keyboard.
o Menu oriented systems- A menu is a multiple choice set of text strings or icons
which are graphic symbols that represent object or operations. The user can
perform actions by selecting items from the menu. Some systems have the most
used functions on a main command menu and have secondary menus to handle the
less frequently used functions.
5.1.3Editor Structure:
Most text editors have a structure similar to that shown in the following figure. That is most
text editors have a structure similar to shown in the figure regardless of features and the
computers
The command language processor accepts input from the user’s input devices and analyses
the tokens and syntactic structure of the commands. That is, it function like lexical and
syntactic phases of a compiler. It invokes the semantic routines directly. The command
language processor also produces an intermediate representation of the desired editing
operations. This representation is decoded by an interpreter that invokes the appropriate
semantic routines.
Editing Component - In editing a document, the start of the area to be edited is determined
by the current editing pointer maintained by the editing component. Editing component is a
collection of modules dealing with editing tasks. Current editing pointer can be set or reset
due to next paragraph, next screen, cut paragraph, paste paragraph etc..,.
Travelling component – performs the setting of the current editing and viewing pointers and
thus determines the point at which the viewing/editing filtering begins.
Editing filter- When 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 pointer as well as on the editing filter parameters.
Viewing component- thee start of the area to be viewed is determined by the viewing pointer.
This pointer is maintained by the viewing component. When the display need to be updated the
viewing component invokes the viewing filter. This component filters the document to
generate a new viewing buffer.
Display component- The viewing buffer is then passed to the display component which
produces a display by mapping the buffer to a rectangular subset of the screen called window.
2. Display component – takes this ideal view from viewing component and maps it
to the output device.
Simple relationship
between editing and
viewing buffers
The components
of the editor deal
with a user
document
on two levels: In
main memory and in the disk file system. Loading an entire document into main memory may
be infeasible – only part is loaded – demand paging is used – uses editor paging routines.
Documents may not be stored sequentially as a string of characters. Uses separate editor data
structure that allows addition, deletion, and modification with a minimum of I/O and character
movement.
Many editors use terminal control database. They can call terminal independent library
routines such as scroll down, or read cursor positions.
Types of editors based on computing environment: Editors function in three basic types of computing
environments:
1. Time sharing
2. Stand-alone
3. Distributed.
Each type of environment imposes some constraints on the design of an editor.
In time sharing environment, editor must function swiftly within the context of the load on the
computer’s processor, memory and I/O devices.
In stand-alone environment, editors on stand-alone system are built with all the functions to
carry out editing and viewing operations – The help of the OS may also be taken to carry out
some tasks like demand paging.
In distributed environment, editor has both functions of stand-alone editor; to run
independently on each user’s machine and like a time sharing editor, contend for shared
resources such as files.
An interactive debugging system provides programmers with facilities that aid in testing and
debugging of programs. Many such systems are available during these days. Our discussion
is broad in scope, giving the overview of interactive debugging systems – not specific to any
particular existing system.
Here we discuss
- Debugging methods
One important requirement of any IDS is unit test functions specified by the programmer.
Such functions deal with execution sequencing , which is the observation and control of the
flow of program execution.Eg: The program may be suspended after a fixed number of
instructions are executed. The programmer can define break points. After the program is
suspended debugging commands can be used to diagnose errors.
A Debugging system should also provide functions such as tracing and trace back
Tracing can be used to track the flow of execution logic and data modifications. The control
flow can be traced at different levels of detail – procedure, branch, individual instruction,
and so on.
Trace back can show the path by which the current statement in the program was reached. It
can also show which statements have modified a given variable or parameter. The
statements are displayed rather than as hexadecimal displacements.
A debugging system should consider the language in which the program being debugged is
written. A single debugger – many programming languages – language independent. The
debugger- a specific programming language– language dependent.
The debugging system should be able to deal with optimized code. Many optimizations
involve rearrangement of code in the program.Eg: Separate loops can be combined into
single loop.
Storage of variables- When a program is translated the compiler assigns a home location in
memory for each variables. Variable values can be temporarily held in registers to improve
speed of access. If a user changes the value of a variable in home location while debugging
the modified value might not be used by the program.
The debugging of optimized code requires cooperation from optimized compiler.
Debugging Methods
1. Debugging by Induction
2. Debugging by Deduction
3. Debugging by Backtracking
Debugging by Induction
In induction one proceeds from the particulars to the whole.ie, By starting with the symptoms of
the error in the result of one or more test cases and looking for relationships among the symptoms.
1. Locate the pertinent data: Consider all the available data or symptoms about the problems
2. Organise the data: Pertinent data is structured to allow one to observe patterns of particular
importance and search for contradictions. One such organization structure can be a table.
3. Devise a hypothesis: In this step study the relationship between the clues and devise using
patterns, one or more hypothesis about the cause o the error.
4. Prove the hypothesis: Prove the reasonableness of the hypothesis before proceeding. A failure
to this, results in the fixing of only one symptom of the problem.
Debugging by Deduction
Is a process of proceeding from general theories or premises to arrive at a conclusion.
1. Enumerate all possible cases- The first step is to develop all causes of the error.
2. Use the data to eliminate possible causes- By careful analysis of data particularly by
looking for contradictions attempt to eliminate all possible causes except one.
3. Refine the remaining hypothesis- The possible causes at this point may be correct. But
refine it to be more specific.
For small programs the method of backtracking is more effective to locate errors.
To use this method start at the place in the program where an incorrect result was produced and go
backwards in the program one step at a time. That is executing the program in reverse order to
derive the values of all variables in the previous step. Then the error can be localized.
Device Driver