SPOS Unit 2
SPOS Unit 2
Code obj
Processor Code Assembler
(with macro)
Macro Definition
MACRO Start of Definition
<Macro Name> <List of Parameters [p1, p2, …pn]>
Macro Name (with label or argument(s) which is optional)
-------------
------------- Sequence to be abbreviated
4
-------------
MEND End of Definition
Macro Definition (cont..)
Example:
MACRO
ADDS &arg1, &arg2, &arg3
L 1, &arg1
A 1, &arg2
ST 1, &arg3 5
MEND
Macro Call
<Macro Name> <List of Actual parameters[ a1, a2, …an]>
For Ex.🡪
MACRO
ADDS &arg1=, &arg2=, &arg3=4 Formal Parameter Value
L 1, &arg1 &arg1 D1
A 1, &arg2 &arg2 D2
ST 1, &arg3
MEND &arg3 100
/MACRO CALL
8/4/2021 17
MACRO
ADDS &arg1, &arg2=45, &arg3=
L 1, &arg1
A 1, &arg2
ST 1,&arg3
MEND
Macro calls
◦ DEFINE COS
◦ COS AR
AIF , .FINI, AGO
.FINI :- it is macro label and don’t appear in output of macro processor.
AIF(&count EQ 1).FINI:- The pseuodo op directs the macro processor to
skip the statement labeled .FINI, if “&count” value is 1; otherwise , the
macro processor is to continue with the statement following AIF
pseuodo op.
AGO:- it is unconditional branch pseudo op like “go to”.
8/4/2021 26
Need of Conditional Macro Expansion
Lets consider example:
:
:
LOOP1 A 1, A1
A 2, A2
A 3, A3
:
:
LOOP2 A 1, A3
A 2, A2
:
:
LOOP3
8/4/2021 A 1, A1 30
:
:
A1 DC F’5’
A2 DC F’15’
A3 DC F’10’
Conditional Macro Expansion
MACRO // Expanded Source code
&a0 VARY &CNT, &a1, &a2, &a3
&a0 A 1, &a1
:
AIF (&CNT EQ 1) .FINI LOOP1 A 1, A1
A 2,& a2 A 2, A2
AIF (&CNT EQ 2) .FINI
A 3, &a3
A 3, A3
.FINI MEND :
: :
:
LOOP1 VARY 3, A1, A2, A3 LOOP2 A 1, A1
: A 2, A2
:
:
LOOP2 VARY 2, A3, A2
: :
: LOOP3 A 1, A1 31
LOOP3 VARY 1, A1
:
:
: :
A1 DC F’5’ A1 DC F’5’
A2 DC F’15’
A2 DC F’15’
A3 DC F’10’
A3 DC F’10’
Design of Two pass macro Processor
Pass-1 :
◦ Recognizes Macro Definition
◦ Stores Macro Instruction
Pass-2 :
◦ Recognizes Macro Calls
◦ Expands calls and substitute actual arguments
8/4/2021 33
Specifications of Data Structures
Pass-1 Data structures/ programs :
◦ Source program with macro definitions and macro calls
◦ Output file without macro definitions & with macro calls
◦ Macro Definition Table (MDT)
◦ Macro Name Table (MNT)
◦ Argument List Array (ALA)
◦ Macro Definition Table Counter (MDTC) : Integer Variable
◦ Macro Name Table Counter (MNTC): Integer Variable
1
ADDS 1
2
.
.
8/4/2021 36
Formats of Data Structures (Cont..)
● Macro Definition Table (MDT)
MDTC Macro Definition Instruction Entry (80 bytes per entry)
1
& Lab ADDS &A1, &A2
2 #0 A 1, #1
3 A 1, #2
4 MEND
5
:
:
:
Formats of Data Structures (Cont..)
0 &Lab -
1 &A1 -
2 &A2 -
8/4/2021 38
3
:
:
Pass1 No
MDTC 🡨 1
END Yes GO TO
Pseudo
MNTC🡨 1 op ? PASS2
MACRO
Pseudo No
op ? Read Next Source Card
Yes
Prepare macro name card
Read Next Source Card and add into MDT Substitute index Notation
for Arguments
Enter Macro Name &
MDTC🡨MDTC+1
Current value of MDTC in
MNT Enter Line into MDT
8/4/2021
5
6
34
PASS 2
Read Next Source card
8/4/2021 46
Grammar is a set of production rules that defines the syntax of a language
Terminals: A set of terminals which we also refer to as tokens, these set of tokens forms strings.
Non-Terminals: CFG has a set of non-terminals (variables). These variables represent the set of
strings. Further, they contribute to the formation of a language generated by grammar.
Production: A grammar has a set of production rules. These rules specify how to combine
terminals and non-terminals to form a string
Symbol
Table
Symbol Table Entries
We will store the following information about identifiers.
Code Generator
[Intermediate Code Generator]
Tokens
Semantic Process
Code Generator
8/4/2021 [Semantic analyzer]
Target machine
Abstract Syntax Tree w/ Attributes code
59
Interpreter
It is a translator (language processor) which directly executes
operations specified in source program on input supplied by
user.
SOURCE PROGRAM
Interpreter Output
Input
8/4/2021 60
Interpreter vs Compiler
Interpreter Compiler
Scans the entire program and translates it as a whole into
Translates program by one statement at a time.
machine code.
It takes less amount of time to analyze the source code It takes large amount of time to analyze the source code
but the overall execution time is slower. but the overall execution time is comparatively faster.
No intermediate object code is generated, hence less Generates intermediate object code which further
memory are required. requires linking, hence requires more memory.
Continues translating the program until the first error is It generates the error message only after scanning the
met, 8/4/2021
in which case it stops. Hence debugging is easy. whole program. Hence debugging is comparatively 61
hard.
goes.
▪Macros are either built-in or user-defined, and can take any number of
arguments.
8/4/2021 62
https://www.gnu.org/software/m4/
Case Study- GNU m4 Macro Processor
1. m4 is a general-purpose macro processor included in most
Unix-like operating systems,
8/4/2021 64
Example of Macro in C
language
#include <stdio.h>
#define NAME "TechOnTheNet.com"
#define AGE 10
int main()
{
printf("%s is over %d years old.\n", NAME, AGE);
return 0;
}
References
1) John Donovan, “Systems Programming”, McGraw Hill, ISBN 978-0--07-460482-3
2) Dhamdhere D., "Systems Programming and Operating Systems", McGraw Hill, ISBN 0 - 07 - 463579 – 4
3) https://www.gnu.org/software/m4/manual/m4.html#Syntax
Ebooks:
▪ https://www.elsevier.com/books/systems-programming/anthony/978-0-12-800729-7
▪ https://www.kobo.com/us/en/ebook/linux-system-programming-1
▪ https://www.e-booksdirectory.com/details.php?ebook=9907
▪ https://onlinecourses.nptel.ac.in/noc19_cs50/preview
▪ https://www.udemy.com/course/system-programming/
Thank You !!
8/4/2021 67