-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSPSIL.tex
262 lines (180 loc) · 11.1 KB
/
SPSIL.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
%\documentclass[11pt]{article}
%\usepackage{tabularx}
%\usepackage{listings}
%\usepackage{verbatim}
%\usepackage[bookmarks]{hyperref}
%
%
%\title{SPSIL \\ Language Specification \\
%Version 1.0}
%\author{Dr. K. Muralikrishnan \\ \texttt{kmurali@nitc.ac.in} \\ {NIT Calicut} }
%
%
%\hypersetup{
%colorlinks=false,
%urlcolor=cyan,
%pdfborder= 0 0 0
%}
%
%
%\begin{document}
\chapter{SPSIL}
\newcommand{\kw}[1]{\texttt{#1}}
%.......................Title Page.................................>%
%\maketitle
%\pagebreak
%......................Table of Contents............................%
\thispagestyle{plain}
%\tableofcontents
%\pagebreak
%...............................Introduction..........................%
\section{Introduction}
%\paragraph{}
\textit{SPSIL} or \textit{System Programmer's Simple Integer Language} is an untyped programming language designed for implementation of an operating system on ESIM \textit{(Extended Simple Integer Machine)} architecture. The language is minimalistic and consists only of basic constructs required for the implementation. Programming using SPSIL requires a basic understanding of the underlying ESIM architecture and operating system concepts.
%-----------------------------Lexical Elements-------------------------%
\section{Lexical Elements}
%*********%
\subsection{Comments and White Spaces}
SPSIL allows only single line comments. Comments start with the character sequence \textbf{//} and stop at the end of the line.
White spaces in the program including tabs, newline and horizontal spaces are ignored.
%*********%
\subsection{Keywords}
The following are the reserved words in SPSIL and it cannot be used as identifiers.
\begin{tabular}{c c c c c }
\kw{alias} & \kw{else} & \kw{if} & \kw{store} & \kw{while} \\
\kw{define} & \kw{endif} & \kw{ireturn} & \kw{strcmp} & \kw{continue}\\
\kw{break} & \kw{do} & \kw{endwhile} & \kw{load} & \kw{then}
\end{tabular}
%*********%
\subsection{Operators and Delimiters}
The following are the operators and delimiters in SPSIL \\
\begin{tabular}{c c c c c c c c c c c c }
( & ) & ; & [ & ] &
/ & * & + & - & \% \\
\textgreater & \textless & \textgreater = & \textless = & != & == & = & \&\& & $\Vert$ & ! \\
\end{tabular}
%*********%
\subsection{Registers}
SPSIL allows the use of 20 registers for various operations.(R0-R7, S0-S7, BP, SP, IP, PID)
%*********%
\subsection{Identifiers}
Identifiers are used as symbolic names for constants and aliases for registers. Identifiers should start with an alphabet but may contain alphabets, digits and/or underscore (\_). No other special characters are allowed in identifiers.
%*********%
\subsection{Literals}
Only integer literals are permitted in SPSIL. An integer literal is a sequence of digits representing an integer. Negative integers are represented with a negative sign preceding the sequence of digits.
%-----------------------------Registers-------------------------%%
\section{Register Set}
SPSIL doesn't allow the use of declared variables. Instead a fixed set of registers is provided. The register set in SPSIL contains 20 registers. There is a direct mapping between these registers and the machine registers in ESIM. \\
\begin{center}
\begin{tabular}{| c | c | }
\hline
R0-R7 & Program Registers \\
\hline
S0-S7 & Kernel Registers \\
\hline
BP & Base Pointer \\
\hline
SP & Stack Pointer \\
\hline
IP & Instruction Pointer \\
\hline
PID & Process Identifier \\
\hline
\end{tabular}
\end{center}
\subsection{Aliasing}
Any register can be referred to by using a different name. A name is assigned to a particular register using the \textbf{alias} keyword. Each register can be assigned to only one alias at any particular point of time. However, a register can be reassigned to a different alias at a later point. Aliasing can also be done inside the \textbf{if} and \textbf{while} block. However, the alias will only be valid within the if and while block it is defined in. The already defined alias for the register(if any) will only be hidden inside if and while blocks. No two registers can have the same alias name simultaneously.
%-----------------------------Constants-------------------------%%
\section{Constants}
Symbolic names can be assigned to values using the \textbf{define} keyword. Unlike aliasing, two or more names can be assigned to the same value. A constant can only be defined once in a program.
\subsection{Predefined Constants}
SPSIL provides a set of predefined constants. These predefined constants can be assigned to different values explicitly by the user using \textbf{define} keyword. These constants are mostly starting addresses of various OS components in the memory.
The predefined set of constants provided in SPSIL are \\
\begin{center}
\begin{tabular}{| c | c |}
\hline
\textbf{Name} & \textbf{Default Value} \\
\hline
SCRATCHPAD & 256 \\
\hline
PAGE\_TABLE & 512 \\
\hline
MEM\_LIST & 576 \\
\hline
FILE\_TABLE & 640 \\
\hline
READY\_LIST & 736 \\
\hline
PROC\_TABLE & 767 \\
\hline
FAT & 1024 \\
\hline
DISK\_LIST & 1536 \\
\hline
USER\_PROG & 1792 \\
\hline
INTERRUPT & 13824 \\
\hline
\end{tabular}
\end{center}
%----------------------------Expressions-------------------------_%
\section{Expressions}
An expression specifies the computation of a value by applying operators to operands. SPSIL supports arithmetic and logical expressions.
\subsection{Arithmetic Expressions}
Registers, constants, and 2 or more arithmetic expressions connected using arithmetic operators are categorized as arithmetic expressions. SPSIL provides five arithmetic operators, viz., +, -, *, / (Integer Division) and \% (Modulo operator) through which arithmetic expressions may be combined. Expression syntax and semantics are similar to standard practice in programming languages and normal rules of precedence, associativity and paranthesization hold.
\subsection{Logical Expressions}
Logical expressions may be formed by combining arithmetic expressions using relational operators. The relational operators supported by SPSIL are \begin{verbatim} <, >, <=, >=, ==, !=
\end{verbatim}
Standard meanings apply to these operators. A relational operator will take in two arguments and return 1 if the relation is valid and 0 otherwise. Logical expressions themselves may be combined using logical operators, \&\& (logical and) , $\Vert$ (logical or) and ! (not).
\subsection{String Comparison}
The only operation that can be performed on strings stored in memory is string camparison. \textbf{strcmp} is used to compare two strings whose address is stored in the registers that are given as operands. \\
e.g. \textit{strcmp(R2,R5)}
\subsection{Addressing Expression}
Memory of the meachine can be directly accessed in an SPSIL program. A word in the memory is accessed by specifying the addressing element, i.e. memory location within [ ]. This corresponds to the value stored in the given address. An arithmetic expression or an addressing expression can be used to specify the address. \\
Examples of addressing expressions: \\\
[1024], [R3], [R5+[S7]+128], [FAT + (PID*16) + S2] etc.
%-----------------________Statements---------------------------_%
\section{Statements}
Statements control the execution of the program. All statements in SPSIL are terminated with a semicolon ;
\subsection{Define Statement}
Define statement is used to define a symbolic name for a value. Define statements should be used before any other statment in an SPSIL program. The keyword \textbf{define} is used to associate a literal to a symbolic name. \\
\textit{ \textbf{define} constant\_name value; }
\subsection{Alias Statement}
An \textbf{alias} statement is used to associate a register with a name. \textbf{Alias} statements can be used anywhere in the program except within \textbf{if} and \textbf{while} statements.\\
\indent \textit{ \textbf{alias} alias\_name register\_name ;} \\
\subsection{Assignment Statement}
The SPSIL assignment statement assigns the value of an expression or value stored in a memory address to a register or a memory address. \textbf{=} is the assignment operator used in SPSIL. The operand on the right hand side of the operator is assigned to the left hand side. The general syntax is as follows \\
\indent \textit{ Register / Alias / [Address] = Expression / [Address] ;}
\subsection{strcpy Statement}
The SPSIL \textbf{strcpy} statement copies a string in one memory location to another memory location. Registers which store the memory location of the destination and the source are given as R{\tiny d} and R{\tiny s} respectively.\\
\indent \textit{ \textbf{strcpy}(R{\tiny d}, R{\tiny s});}
\subsection{If Statement}
\textbf{If} statements specify the conditional execution of two branches according to the value of a logical expression. If the expression evaluates to 1, the \textbf{if} branch is executed, otherwise the \textbf{else} branch is executed. The \textbf{else} part is optional. The general syntax is as follows \\
\textit{
\textbf{if} (logical expression) \textbf{then} \\
\indent \indent statements; \\
\indent \textbf{else} \\
\indent \indent statements; \\
\indent \textbf{endif;} \\
}
\subsection{While Statement}
\textbf{While} statement iteratively executes a set of statements based on a condition. The condition is defined using a logical expression. The statements are iteratively executed as long as the condition is true.\\
\textit{
\textbf{while} (logical expression) \textbf{do} \\
\indent \indent statements; \\
\indent \textbf{endwhile;} \\
}
\subsection{Break statement}
\textbf{Break} statement is a statement which is used in a while loop block. This statement stops the execution of the loop in which it is used and passes the control of execution to the next statement after the loop. This statement cannot be used anywhere else other than while loop. The syntax is as follows\\
\textit{\textbf{break} ;}
\subsection{Continue statement}
\textbf{Continue} statement is a statement which is also used only in a while loop block. This statement skips the current iteration of the loop and passes the control to the next iteration after checking the loop condition. The syntax is as follows\\
\textit{\textbf{continue} ;}
\subsection{ireturn Statement}
\textbf{ireturn} statement is used to pass control from kernel mode to user mode. The \textbf{ireturn} is generally used at the end of an interrupt code.
\textit{\textbf{ireturn};}
\subsection{Load / Store Statements}
Loading and storing between filesystem and memory is accomplished using \textbf{load} and \textbf{store} statements in SPSIL. \textbf{load} statement loads the block specified by \textit{block\_number} from the disk to the the page speficied by the \textit{page\_number} in the memory. \textbf{store} statement stores the page specified by \textit{page\_number} in the memory to the the block speficied by the \textit{block\_number} in the disk. The page number and block number can be specified using arithmetic expressions.
\textit{\textbf{load} (page\_number, block\_number);}
\textit{\textbf{store} (page\_number, block\_number);}
%\end{document}