•
Module1 Module 1 Module 1 Module 1
Module 1 Memory structure same as SIC. Maximum Example: +JSUB RDREC( jump to the address
memory available on a SIC/XE system is 1 RDREC). • It translates only one statement
1. Explain the SIC The flag bit x is used to indicate indexed
Megabyte (220 bytes). Formats 1 and 2 are instructions do not of a program at a time. It reads only one
• This increase leads to change reference memory at all. statement, translate it and execute it. Then it
machine architecture. addressing mode. in instruction formats and addressing modes. reads the next statement and do the same till
• SIC machine architecture can Addressing Modes all the statements are translated and executed.
be considered with respect to its Memory and Registers 1. Base Relative • The main difference with that of
Registers, Data Formats, Instruction Formats, 8 1 15 • Additional B, S, T, and F 2. Program Counter relative compiler is, compiler goes through the entire
Addressing Modes, Instruction Set, Input and registers are provided by SIC/XE, in addition 3. Base relative with indexing program and then translate the entire program
Output opcode x address to the registers of SIC. into machine codes.
4. Program counter relative
Memory: addressing • So compiler is 5 to 25 times
5. Direct Addressing faster than interpreter.
Addressing Modes: Mnemonic Number Special use 6. Immediate addressing • An interpreter is a small
• There are 215 bytes in the B 3 Base register 7. Indirect addressing Compiler program compared to compiler. It occupies
computer memory, that is 32,768 bytes. 3 S 4 General less memory space, so it can be used in a
consecutive bytes form a word(24) bits .Each Mode Indication Target address working register smaller system which has very limited
location in memory contains 8-bit bytes. All calculation T 5 General memory space.
addresses on SIC are byte addresses. Words Direct x=0 TA = address working register 3.1 Compiler: • By compiler, the machine
are addressed by the location of their lowest Indexed x=1 TA = address + F 6 Floating-point _ it is a program that translates a high level codes are saved permanently for future
numbered byte. (x) language into a machine language. references. On the other hand, machine codes
accumulator (48 bits)
Registers: produced by interpreter are not saved.
• Compiler is more intelligent
•There are five registers, each 24 bits in Data Format than an assembler.
length. Their mnemonic, number and use are • There are two addressing •
• Same data format as SIC. Compiler checks all kinds of
given in the following table. modes available, which are as shown in the limits, ranges, errors etc.
• There is a 48-bit floating-point
above table.. data type, F*2(e-1024) • Its program run time is more
• Parentheses are used to and occupies a larger part of memory. 4.1System Software
Mnemonic Number Use indicate the contents of a register or a memory • Since the compiler goes • It is a set of programs that
A 0 Accumulator; location. through the entire program and then
1 11 36 supports the operation of a computer.
used for arithmetic operations • The table describes how the translates the entire program in to machine
s exponent fraction • It is a set of programs to
X 1 Index register; target address is calculated from the address codes, it has slow speed. perform a variety of system functions as file
used for addressing given in the instruction. • Eg: C program, C++, C# etc.
Instruction Formats: editing, resource Management, I/O
L 2 Linkage • Types of Compiler o Single management and storage management.
register; JSUB Instruction Set : Pass Compiler: Source code is directly • System software is intended to
PC 8 Program transforms into machine code o Two Pass
The new set of instruction formats for SIC/XE support the operation and use of the computer
counter Compiler
machine architecture are as follows. itself, rather than any particular application.
SW 9 Status word, 1. SIC provides, load and store ▪ Two pass Compiler is divided into two For this reason, they are usually related to the
including CC instructions (LDA, LDX, STA, STX, etc.). sections
• Format 1 (1 byte): contains architecture of the machine on which they are
Data Formats: 2. Integer arithmetic operations: • Front end: It maps legal code
only operation code run.
(ADD, SUB, MUL, DIV, etc.). All arithmetic into Intermediate Representation (IR). • It acts as an intermediary
operations involve register A and a word in • Back end: It maps IR onto the between computer hardware and application
• Integers are stored as 24-bit memory, with the result being left in the target machine programs.
Example: RSUB
binary numbers. 2’s complement register. Two instructions are provided for
• Format 2 (2 bytes): first eight o Multi Pass Compiler • It controls the computer
representation is used for negative values, subroutine linkage. system and enhances its performance.
characters are stored using their 8-bit ASCII bits for operation code, next four for register 1 ▪ The multipass compiler
3. COMP compares the value in • Eg: Operating system,
and following four for register 2. The numbers processes the source code of a program
Memory- register A with a word in memory, this Compiler, Debugger, Assembler, Interpreter
for the registers go according to the numbers several times.
Memory structure same as SIC. Maximum memory available on a SIC/XE system is 1 Megabyte (220
instruction sets a condition code CC to etc.
bytes).
indicated at the registers section (ie, register ▪ It divided a large program into
This increase leads to change in instruction formats and addressing modes. indicate the result. There are conditional jump
T is replaced by hex 5, F is replaced by hex 6). multiple small programs and process them. ▪ 4.2 Application Software
instructions: (JLT, JEQ, JGT), these
Registers It develops multiple intermediate codes. • Application software consists
Additional B, S, T, and F registers are provided by SIC/XE, in addition to the registers of
instructions test the setting of CC and jump
SIC.
accordingly. -All of these multipass take the output of the of programs designed to perform specific
previous phase as an input. So it requires less tasks for users.
Mnemonic Number Special use 4. JSUB jumps to the subroutine
Example: COMPR A,S memory • It performs particular functions
B 3 Base register placing the return address in register L, RSUB
S 4 General working register returns by jumping to the address contained • Format 3 (3 bytes): First 6 bits •Different phases of compilation: for the user.
in register L. contain operation code, next 6 bits contain • It is program written for or by a
T 5 General working register
5. Input and Output: Input and flags, last 12 bits contain displacement for the user to perform a particular job.
F 6 Floating-point accumulator (48 bits)
Output are performed by transferring 1 byte at address of the operand. Operation code uses • An application program is
a time to or from the only 6 bits, thus the second hex digit will be primarily concerned with the solution of some
Data Format
affected by the values of the first two flags (n problem, using the computer as a tool.
Same data format as SIC.
There is a 48-bit floating-point data type, F*2(e-1024) and i). The flags, in order, are: n, i, x, b, p, and • Application software lies on
rightmost 8 bits of register A (accumulator).
e. The last flag e indicates the instruction the top of the system software, because it is
1 11 36
The Test Device (TD) instruction tests whether
format (0 for 3 and 1 for 4). Example: LDA #3 unable to run without the operating system
s exponent fraction
the addressed device is ready to send or
receive a byte of data. Read Data (RD), Write and system utilities.
Instruction Formats:
Data (WD) are used for reading or writing the Format 4 (4 bytes): same as format 3 with an • Application software can be
The new set of instruction formats for SIC/XE machine architecture are as follows.
data extra 2 hex digits (8 bits) for addresses that used to assist with graphics and multimedia
codes. No floating-point hardware on the require more than 12 bits to be represented. projects, to support home, personal and
standard version of SIC. 2. Explain SIC/XE educational activities and to facilitate
Instruction Formats: machine architecture communications.
Memory- • Eg: Oracle, MS Access, Word
• All machine instructions on the
•
3.2 Interpreter processors, Web browsers, Spread sheets,
standard version of SIC have the 24-bit format • It is a program that translates Media Player, MS PowerPoint etc.
as shown below. statements of a program into machine code.
Module 2 Module 2 Module 2 Module 2 Module 3
1. Two Pass Algorithm Pass2 2• Assembler data structures [Link]-Pass Assembler
Assembler {
o Assembler uses three main data 3• Basic Functions of an
structures The main problem in designing the assembler
Read the first input line from Assembler
Algorithm intermediate file
▪ Location Counter(LOCCTR) 1. Convert mnemonic operation codes to their
using single pass was to resolve forward
references. We can avoid to some extent the
If OPCODE = ‘START’ ▪ Operation Code Table(OPTAB) machine language equivalents forward references by:
{ ▪ Symbol Table(SYMTAB) ▪ Eg: Translate STL to 14
Algorithm Pass1 Write the line into assembly listing
2. Convert symbolic operands to their Eliminating forward reference to data items, by
{
o LOCCTR equivalent machine addresses defining all the storage reservation statements
Read next input line ▪ It is a variable that is used to help in the ▪ Eg: Translate the operand RETADR to at the beginning of the program rather at the
Read the input line } assignment of addresses. 1033(address of RETADR) end
If OPCODE=’START’ Write Header records to object ▪ LOCCTR is initialized to be the beginning 3. Convert the data constants to internal • Unfortunately, forward
{ address specified in the “START” machine representations reference to labels on the instructions cannot
program
starting address = #OPERAND statement ▪ Eg: Translate EOF to 454F46 be avoided. (forward jumping)
Initialize first Text record ▪ After each statement is processed, the length 4. Build the machine instructions in the proper • To provide some provision for
LOCCTR = starting address While OPCODE != ‘END’ do handling forward references by prohibiting
of the assembled instruction or data format
Write line to intermediate file { area to be generated is added to LOCCTR 5. Write the object program and the assembly forward references to data items
Read next input line If this is not a comment line • LOCCTR = LOCCTR + (instruction length/size listing
} of data area) o The assembler must also process
{
Else ▪ The current value of LOCCTR gives the statements called assembler directives or There are two types of one-pass
Search OPTAB for OPCODE address to the label encountered pseudo
LOCCTR = 0 If found instructions which are not translated into assemblers:
While OPCODE != ‘END’ do o OPTAB machine instructions. Instead they provide
{
{ ▪ It must contain the mnemonic operation code instructions to the assembler itself • One that produces object code
If there is a symbol in OPERAND field and its machine language equivalent. directly in memory for immediate execution
Write line to intermediate file along ▪ RESB and RESW- instruct the assembler to
{ ▪ Used to lookup mnemonic operation codes reserve memory locations without (Load- and-go assemblers).
with LOCCTR Search SYMTAB for operand and translate them to their machine • The other type produces the
generating data values.
If this is not a comment line If found language equivalent. ▪ BYTE and WORD – direct assembler to usual kind of object code for later execution.
{ ▪ It may contain instruction format and length. generate constants as part of the object
Store symbol value as operand
If there is a symbol in the label field ▪ In Pass 1: program Load-and-Go Assembler
address • OPTAB is used to look up and validate
{ o All of these functions except number 2 can
Else operation code in the source program. easily be accomplished by sequential
Search SYMTAB for LABEL • Load-and-go assembler generates their
Set error flag • Must search the OPTAB to find the processing of the source program, one line at object code in memory for immediate
If found } instruction length for incrementing a time. execution.
Set error flag(Duplicate Symbol) LOCCTR.
Else o The difficulty with number 2 is: • No object program is written
▪ In Pass 2
Else Set 0 as operand address out, no loader is needed.
• OPTAB is used to translate the operation
Insert (LABEL, LOCCTR) into SYMTAB Assemble the object code instruction codes to machine language. [Link] Program format
} • It is useful in a system with
} • It is used to find which instruction format is • The simple object program contains three
frequent program development and testing
Search OPTAB for OPCODE used. types of records: Header record, Text record
Else if OPCODE = ‘BYTE’ or ‘WORD’ o The efficiency of the assembly process is an
If found ▪ The information in OPTAB is predefined dand end record.
Convert constant to object code important consideration.
when the assembler itself is written. • The header record contains the
LOCCTR = LOCCTR + 3 If object code will not fit into the • Programs are re-assembled
▪ Implementation starting address and length. Text record
Else if OPCODE = ‘WORD’ current Text record • Design a special hash table with mnemonic contains the translated instructions and data
nearly every time they are run; efficiency of
the assembly process is an important
LOCCTR = LOCCTR + 3 { operation code as the key. It of the program, together with an indication of
consideration.
Else if OPCODE = ‘RESW’ Write Text record to object program provides fast retrieval with minimal searching. the addresses where these are to be loaded.
• It is a static table. Entries are not normally The end record marks the end of the object
LOCCTR = LOCCTR + 3 x #[OPERAND] Initialize new Text record MultiPass Assembler:
added to or retrieved from it. program and specifies the address where the
Else if OPCODE = ‘RESB’ } execution is to begin.
LOCCTR = LOCCTR + #[OPERAND] o SYMTAB For a two pass assembler, in EQU assembler
Add object code to Text record ▪ SYMTAB contains name and address for
The format of each record is as given directive we required that any symbol on the
Else if OPCODE = ‘BYTE’ } each label in the source program, together below. right hand side be defined previously in the
LOCCTR = LOCCTR + length of Write the line into assembly listing with flags to indicate error conditions (Ex: Header record: program. This is because o the two [Link]
constant in bytes along with object code symbols defined in two different places). Col 1 H multipass is possible this restriction can be
Else ▪ It may also contain label type, length etc. avoided. Eg:
Read next input line Col. 2-7 Program name
Set error flags ▪ Pass 1: Labels are entered in to SYMTAB
} along with their assigned addresses (from ALPHA
} Write last Text record to object LOCCTR) Col 8-13 Starting address of object EQU
Read next input line program ▪ Pass 2: Operands are looked up in SYMTAB program (hexadecimal) Col 14-19 BETA BETA EQU
} Write End record to object program to obtain the addresses to be inserted Length of object program in DELTA DELTA
in the assembled instructions. bytes (hexadecimal) Text record: RESW 1
Write last line to intermediate file Write last listing line
▪ It is a dynamic table Col. 1 T
Save (LOCCTR – starting address) as } • Usually organize as a hash table for
program length. efficiency of insertion and retrieval. Col 2-7. Starting address for object Working of Multipass Assembler:
} • Choose the hash function carefully code in this record (hexadecimal) Col 8-9 • A multipass assembler can
Length off object code in this make as many passes as needed to process
record in bytes (hexadecimal) the definition of symbols.
Col 10-69 Object code, represented in • For a forward reference in
hexadecimal (2 columns per byte of object symbol definition, we store in the SYMTAB:
code) o The symbol name
Module 3 Module 3 Module 4 Module 4 Module 4
o The defining expression • The above diagram shows the
O (1) Algorithm for a Pass 2 Linking Loader
o The number of undefined concept of relocation. Initially the program is Linking Loader Algorithm
symbols in the defining expression loaded at location 0000. The instruction JSUB
is loaded at location 0006.
CSADDR = PROGADDR \\ for the
• The undefined symbol (marked
with a flag *) associated with a list of symbols
depend on this undefined symbol.
• The address field of this
instruction contains 01036, which is the
address of the instruction labeled RDREC. The
Pass 1 Linking Loader 1st control section o (2) Absolute loader
Get PROGADDR from OS EXECADDR = PROGADDR
• When a symbol is defined, we second figure shows that if the program is to
can recursively evaluate the symbol be loaded at new location 5000. CSADDR = PROGADDR \\ for While not end of input do The object code is
expressions depending on the newly defined - • The address of the instruction
symbol. JSUB gets modified to new location 6036. the 1st control section { loaded to the specified location
Likewise the third figure shows that if the While not end of input do Read the next input record \\ in the memory.
[Link] Relocation program is relocated at location 7420, the
{ All functions are
• Sometimes it is required
JSUB instruction would need to be changed to header record for the control
4B108456 that correspond to the new address
Read the next input record \\ section accomplished in a single pass as
to load and run several programs at of RDREC.
follows:
the same time. The system must be • The only part of the program header record for the control CSLTH = control section
able to load these programs wherever that require modification at load time are those • The Header record of
there is place in the memory. that specify direct addresses(format 4 section length object programs is checked to
Therefore the exact starting is not
instructions). The rest of the instructions need
not be modified. The instructions which
CSLTH = control section While record_type != ‘E’ do verify that the correct program
known until the load time. doesn’t require modification are the ones that length { has been presented for loading.
• Absolute Program- In this is not a memory address (immediate
addressing) and PC-relative, Base-relative Search ESTAB for the Read the next input record • As each Text record is
the address is mentioned during
assembling itself. This is called instructions. control section name If record_type = ‘T’ then read, the object code it contains
• For an address label, its is moved to the indicated
Absolute Assembly. address is assigned relative to the start of the If found then {
Eg: Consider the instruction: program (START 0). The assembler produces address in memory.
Set error flag If the object code is in character
101B LDA THREE 00102D a Modification record to store the starting • When the End record
location and the length of the address field to Else form then
be modified. The command for the loader must
is encountered, the loader jumps
•This statement says that the register Enter control section name Convert it into internal
also be a part of the object program. The to the specified address to begin
A is loaded with the value stored at representation
location 102D. Suppose it is decided to
Modification has the following format: and CSADDR into ESTAB execution of the loaded program.
Move the object code from
load and execute the program at Modification record While record_type != ‘E’ do record to location (CSADDR +
No linking and
location 2000 instead of location 1000. { relocation needed.
Col. 1 M specified address)
• Then at address 102D the
required value which needs to be
Read the next input record }
Col. 2-7 Starting location of the address
loaded in the register A is no more field to be modified, relative to the beginning If record_type = ‘D’ then Else if record_type = ‘M’ then Algorithm
available. The address also gets of the program (Hex) { {
Col. 8-9 Length of the address field to
begin
changed relative to the displacement Search ESTAB for modification
of the program. Hence we need to be modified, in half-bytes (Hex) For each symbol in the read Header record
symbol name
make some changes in the address record do verify program name and length
One modification record is created for each If found then
portion of the instruction so that we address to be modified The length is stored in { read first Text record while
can load and execute the program at half-bytes (4 bits) The starting location is the
Add or subtract the symbol record type 'E' do
location 2000. location of the byte containing the leftmost Search ESTAB for symbol value at location (CSADDR +
begin
• Apart from the instruction bits of the address field to be modified. If the name specified address)
which will undergo a change in their field contains an odd number of half-bytes, the {if object code is in character
starting location begins in the middle of the If found then Else form, convert into internal
operand address value as the program first byte.
Set error flag Set error flag representation} move object
load address changes. There exist
some parts in the program which will Else } code to specified location in
remain same regardless of where the } memory read next object
Enter symbol and (CSADDR
program is being loaded.
Eg: Consider the instruction
If an address is specified in End program record
• Since assembler will not CLOOP +JSUB RDREC
+ indicated address) into record then end
know actual location where the 4B101036 ESTAB EXECADDR = CSADDR +
program will get loaded, it cannot where RDREC is at the address 1036. The jump to address specified in End
make the necessary changes in the modification record for this instruction can be } specified address record
addresses used in the program. written as } CSADDR = CSADDR + CSLTH end
M00000705
However, the assembler • There is one modification } }
identifies for the loader those parts of record for each address field that needs to be Jump to location given by
CSADDR = CSADDR +
the program which need modification. changed when the program is relocated(ie. For EXECADDR to start execution of continuation next page
• An object program that each format 4 instructions in the program). CSLTH //starting address of
the program
has the information necessary to the next control section
perform this kind of modification is
called the relocatable program.
}
Module 4 continuation After loading the OS, Module 4 Module 4
the control is transferred to the Module 4
instruction at address 0x80.
(6)Loader Design
• Each pair of bytes from
the object program record must be (5) Data structures for a •Loaders do loading , Algorithm for the
packed together into one byte during linking loader relocation and linking. Bootstrap Loader
loading. •Consider the algorithm for a
• Eg: Opcode for STL is 14.
linking and relocating loader.
•There are 4 types
It is saved in object program as 2
•We use modification records for Linkage editor- links the Begin
bytes(2 characters). While loading it is
converted to single byte(00010100). both relocating and linking program stores it in a file and X=0x80 (the address of
• The content of the •This type of loader is found on later loads. the next memory location
memory location for which there is no SIC/XE machines whose relative
Text record are shown as xxxx.
Linking loader- linking to be loaded.)
addressing makes relocation
Advantage: during load time Loop
unnecessary.
• Simple Dynamic linking-
•
•Input- consists of a set of object A-GETC (and convert it
Efficient(less space and
(4) Differences between linking during execurion time
loading time) programs (control sections) that from the ASCII character
Bootstrap loader- loads the first
Disadvantage: Linkage editor and linking are to be linked together.
program or OS. code to the value of the
•Programme should specify the actual loader •Control sections or programs
address contain external references
Dynamic Linking hexadecimal digit) save
o If the system having small a) linking loader •In dynamic linking the linking
whose definition does not appear the value in the high-
memory, only one program can run at function is done at execution
a time. So it does not create much *Performs all linking and in the same program or control
section. So linking can not be time. That is a subroutine is order 4 bits of S
difficulty to specify the address.
o On a larger system, we
relocation operations and done until an address is loaded and linked to the rest of A← GETC
gloads the linked program the program when it is first
are supposed to run several assigned to the external symbol.
called.
combine the value to form
independent programs. It is not easy directly into memory for So it requires two passes.
one byte A (A+S) store the
to specify actual address while writing Pass1- Assigns addresses to •Dynamic linking is often used to
execution
programs.
all external symbols. allow several executing value (in A) to the address
• Difficult to
subroutines libraries efficiently.
use
* A linking loader searches Pass2- performs the programs to share one copy of a
subroutine or library. For eg: in C
in register X
o If there are multiple the library and resolves actual loading relocation and X+X+1..
such fuctions are stored in
subroutines, the programmer must
external references every linking.
remember the address of each and use dynamic linking library.. A single End
time the program is • The main data copy of the routines in this
that absolute address explicitly in It uses a subroutine
other subroutines to perform executed. structure for the linking loader library could be loaded into
subroutine linkage. is an external symbol table memory and all programs share
GETC, which is
o Solution:
relocatable programs instead of
Write *More than one pass ESTAB. It is analogous to this. GETC
required SYMTAB. It stores the name and •In object oriented program Aread one character
absolute ones.
address of each external symbol dynamic linking is often used for
(3)Bootstrap Loader b)linkag editor if A=0x04 then jump to
in the control section. The table references to software objects.
It is a special type of 1. Produces a linked version also indicates in which control •Advantage:- Dynamic linking 0x80-
absolute loader. of the program called load section the symbol is defined. provide the ability to load the if A <48 then GETC
When a computer is
module which is written to a • Two variables: routines only when they are A-A-48 (0x30)
first turned on or restarted,
file for later execution PROGADDR- Program starting required. For eg: consider the
bootstrap loader is executed.
subroutine which diagnose the if A < 10 then return
This bootstrap loads 2. Resolution of external address in memory where the
linked program should be error in input data during
the operating system into references and library execution. If such errors are rare
loaded. Its value is supplied to
memory. searching are only these subroutines need not be
The bootstrap itself the loader by the [Link]-
performed once contains the starting address used.
begins at address 0 3. The loading can be •Consider the following example
assigned to the control section
It loads the OS(from of dynamic linking. Here the
accomplished in one pass currently being scanned by the
device F1) starting at address routines that are to be
0x80. and no external symbol table loader.
•Example: Consider the object dynamically loaded must be
The object code required, much less
programs of PROGA, PROGB, called via an OS service request.
having no header record, end overhead than a linking
PROGC in fig 3.9 as input to the
record or control information loader.
loader.
Module 5 Module 5 Module 5 Module 5
(1) Keyword Macro b Generation of Unique (4)ONE PASS MACRO
Parameters (3)Machine-independent Labels PROCESSOR
•All the macro instruction (2) Macro-Processor •it is not possible to use begin (macro processor)
EXPANDING := FALSE while
definitions used positional Features. labels for the instructions OPCODE 'END'
parameters. Parameters and The design of macro Module 5 begin
arguments are matched
processor doesn’t in the macro definition, do
according to their positions GETLINE
depend on the since every expansion of
in the macro prototype and PROCESSLINE
the macro invocation architecture of the macro would include the end (while)
statement. machine. We will be label repeatedly which is end (macro processor)
•The programmer needs to studying some extended not allowed by the procedure PROCESSLINE
begin
be careful while specifying feature for this macro assembler.
search NAMTAB for OPCODE
the [Link] an processor. These •We can use the if found then
argument is to be omitted the features are: technique of generating EXPAND
macro invocation statement else if OPCODE='MACRO' then
•Concatenation of Macro unique labels for every
must contain a null argument DEFINE
mentioned with two Parameters macro invocation and else write source line to
commas. •Generation of unique expansion. expanded file
•Positional parameters are labels c. Conditional Macro end (PROCESSLINE)
procedure DEFINE
suitable for the macro •Conditional Macro Expansion
begin
invocation. But if the macro Expansion In all our previous examples of
enter macro name into NAMTAB
invocation has large number macro instructions, each
•Keyword Macro invocation of a particular macro
enter macro prototype into
of parameters, and if only DEFTAB
Parameters was
few of the values need to be LEVEL := 1
expanded into the same
used in a typical invocation, sequence of statements. These
while LEVEL 0 do
a different type of parameter a)Concatenation begin
statements could be varied by
specification is required. of Macro parameters: the GETLINE
if this is not a comment line then
•Eg: Consider the macro •Most macro processor allows substitution of parameters, but
begin
GENER which has 10 parameters to be concatenated the form of the statements, and
the order in which they appeared substitute positional notation for
parameters, but in a with other character strings. parameters
where [Link] macro
particular invocation of a Suppose that a program contains enter line into DEFTAB if
a series of variables named by processors can modify the
macro only the third and sequence of statements OPCODE MACRO' then
nineth parameters are to be the symbols XA1, XA2, XA3,…,
generated for a LEVEL: LEVEL + 1
another series of variables
specified. macro expansion, depending on else if OPCODE = 'MEND'
named XB1, XB2, XB3,…, etc. If
If positional parameters are similar processing is to be the arguments supplied in the then
used the macro invocation performed on each series of macro invocation. Such a LEVEL: LEVEL - 1
will look like GENER , , labels, the programmer might put capability adds greatly to the
end (if not comment)
power and flexibility of a macro
DIRECT, , , , , , 3, this as a macro instruction. end (while)
language. The term conditional
• But using keyword •The parameter to such a macro store in NAMTAB pointers to
assembly can be used to
parameters this problem can instruction could specify the
describe this beginning and end of
be solved. We can write series of variables to be operated
on (A, B, etc.). The macro
definition
GENER TYPE=DIRECT, end (DEFINE)
processor would use this
CHANNEL=3 parameter to construct the
symbols required in the macro
expansion (XA1, XB1, etc.).
Module 5 Module 5 Module 5
(5)Data Structures used (6)Macro [Link]-Purpose Macro Module 5
in macroprocessor ProcessorDesignOptions Processors
There are three data structures Macro Processing within
involved in one –pass macro • Macro processors Language Translators
processor. A)RecursiveMacro that do not dependent on any
• Preprocessors
1. DEFTAB Expansion particular programming
2. NAMTAB language, but can be used with a
3. ARGTAB variety of different languages
– They process macro
• Pros
o Programmers do not definition and expand
-DEFTAB- The macro need to learn many macro macro invocations,
definitions are stored in a languages. producing an expanded
definition table(DEFTAB) which o Although its
contain the macro definition and development costs are
version of the source
the statements that form the somewhat greater than those for program
macro body. References to the a language specific macro – This expanded program
macro instruction parameters processor, this expense does not
are converted to positional
is then used as input to
need to be repeated for each
notation. language, thus save substantial an assembler or compiler
-NAMTAB- Macro names are overall cost. • Combining the macro
entered into NAMTAB, which • Cons processing function with
serves as an index to DEFTAB. o Large number of
details must be dealt with in a
the language translator
For each macro instruction
defined , NAMTAB contains real programming language itself
pointers to the beginning and Situations in which • Achieved using Line –by
end of the definition in DEFTAB. normal macro parameter –line macro processor
-ARGTAB- is used during the substitution should not occur,
expansion of the macro e.g., comments. – The macro processor
invocation. When a macro Facilities for grouping reads the source program
invocation statement is together terms, expressions, or statements
recognized the arguments are statements. Eg: some languages
use begin and end . Some use {
– Process the statement
stored in argument table. As the
macro is expanded arguments and } – The output lines are
from ARGTAB are substituted for Tokens, e.g., passed to the language
the corresponding parameters in identifiers, constants, operators,
translator as they are
keywords
the macro body. generated, instead of
Syntax used for
macro definition and macro being written to an
invocation statement is different. expanded source file
– Thus macro processor
operates as a sort of input
routine for the assembler
or compiler