System Programming
System Programming
1) Write a Program to create ,read , and write into a file having record of
students.
2) a) Write a program to generate Machine Op-Code Table , Symbol
Table and Pseudo Op- Code table during First Pass Assembler.
b) Write a program to generate Machine Op- code table using Two
pass Assembler.
3) a) Write a program to Generate Macro Name Table , Macro definition
Table and Argument List Array during Pass One of Two Pass
Macro.
b) Write a program to generate Expanded Source in Pass Two of Two
Pass Macro.
4) Study of Lexical Analyzer.
5) Study of Device Drivers.
6) Study and implement general purpose commands in UNIX . ( Date ,
Who , Who am I, Cal, Echo , Clear, Mesg, Mail, and Login
Command)
7) To Study and implement all the directory oriented Commands of
UNIX( Cd , MKdir , rmdir, And Pwd Command)
8) To Study and implement all the File oriented Commands of UNIX( ls-
list files, Cat, cp, rm commands)
9) To study implement HEAD, TAIL , CUT and PASTE commands.
10) To Study Common Object File Format(COFF)
Practical I :
Aim: Write a program to create , read and write into a file having record of
Students.
Theory:
Opening a File
$filename= ‘c:\file.txt’;
$fp = fopen($filename,”r”);
The fopen() function normally uses two parameters. The first is the file
which we want to open. This can be a file on your system. In this example
we are opening a text file on a windows machine . The second parameter is
the “mode”. We can open a file for only reading. We can open a file for only
writing . We can open a file for reading and writing . In the above example
”r” means reading.
After we have opened the file , we will probably want to do something with
it. To read the contents of a file into a variable we use fread().
Now fread() also uses two parameters. The first parameter is the variable to
which we assigned the fopen() function, the second is the number of
bytes we want to read up to in the file. In this case we want to read the
entire file, so we use the filesize() function to get the size of the file
specified in the $filename variable. Thus, it reads the entire file in.
Line1
Line2
Line3
Line4
Line5
Line1
Line2
Line3
Line4
Line5
The contents of the file are read into a string , complete with newline
characters( \n. We can then process this string however we like.
Write To a File:
We can also write data into a file once we have opened it. To do this we use
the fputs() function.
Firstly we open the file. Notice the “a” parameter ? That means “open the
file for writing only, and place the file pointer at the end of the file”.
We then use fputs() to write to the file. We then close the file. So now what
will the file contain/
Line1
Line2
Line3
Line4
Line5
Modes:
There are various modes you can use to open a file, they are listed on the
php.net fopen() function page, but I’ll stick them up on here too.
• ‘r’ – Open for reading only, place the file pointer at the beginning of
the file.
• ‘r+’- Open for reading and Writing ; place the file pointer at the
beginning of the file.
• ‘w’- Open for writing only, place the file pointer at the beginning of
the file and truncate the file to zero length. If the file does not exist ,
attempt to create it.
• ‘a’- Open for writing only, place the file pointer at the end of the file.
If the file does not exist, attempt to create it.
• ‘a+’- Open for reading and writing ; place the file pointer at the end of
the file. If the file does not exist , attempt to create it.
Viva Voice:
Aim:
Theory:
Object code denotes the code to be loaded at given memory location . It can
denote either an executable machine instruction or some data to be stored at
that location.
Assign address to each statement as per the size of each instruction and
addressing modes.
Save values of labels to be used in Pass-II
Process assembler directives , Which affects address assignment .
Write output to an intermediate file.
Viva Voice:
Aim:
Theory:
Implementation :
Statement of Problem:
1. Recognize macro definitions.
2. Save the definitions
3. Recognize calls
4. Expand calls and substitute arguments.
Specification of Databases
Pass II database:
Viva Voice:
Theory:
Lex turns the user’s expressions and actions ( called source in this memo)
into the host general purpose language; the generated program is named
yylex. The yylex program will recognize expressions in a stream ( called
input in this memo) and perform the specified actions for each expression as
it is detected.
+--------------+
+-------------+
+------------+
+ ----------- +
An Overview of Lex
Figure 1
Working of LEX :
%{
code
%}
4) Start conditions, given in the form
%S name1 name2………..
5) Character set tables , in the form
%T
number space character-string
……
%T
6) Changes to internal array sizes, in the form
%x nnn
Where nnn is a decimal integer representing an array size and x selects the
parameter as follows.
Letter Parameter
P Positions
n States
e tree nodes
a transitions
k packed character classes
o output array size
Lines in the rules section have the form “ expression action “ where the
action may be continued on succeeding lines by using braces to delimit it.
Viva Voice:
Theory:
Introduction:
The purpose of a device driver is to handle requests made by the kernel with
regard to a particular type of device. There is a well defined and consistent
interface for the kernel to make these requests. By isolating device specific
code in device drivers and by having a consistent interface to the kernel,
adding a new device is easier.
A device driver is a software module that resides within the Digital Unix
kernel and is the software interface to a hardware device or devices. A
hardware device is a peripheral, such as a disk controller , tape controller , or
network controller device. In general , there is a one device driver for each
type of hardware device. Device drivers can be classified as:
A block device driver is a driver that performs I/O by using file system
block sized buffers from a buffer cache supplied by the kernel. The kernel
also provides for the device driver support interfaces that copy data between
the buffer cache and the address space of a process.
Block device drivers are particularly well- suited for disk drives, the most
common block devices. For block devices , all I/O occurs through the buffer
cache.
A character device driver does not handle I/O through the buffer cache, so it
is not tied to a single approach for handling I/O. You can use a character
device driver for a device such as a line printer that handles one character at
a time. However , character drivers are not limited to performing I/O one
character at a time. ( despite the name “ character” driver) . For example ,
tape drivers frequently perform I/O in 10 K chunks. You can also use a
character device driver when it is necessary to copy data directly to or from
a user process. Because of their flexibility in handling I/O , many drivers are
character drivers . Line printers, interactive terminals, and graphics displays
are examples of devices that require character device drivers.
4. Psedodevice Driver
Not all device drivers control physical hardware . Such device drivers are
called “peudodevice” drivers. Like block and character device drivers ,
pseudodevice drivers make use of the device driver interfaces. Unlike block
and character device drivers, pseudodevice drivers do not operate on a bus.
One example of a pseudodevice driver is the pseudoterminal or pty terminal
driver , which simulates a terminal device . The pty terminal driver is a
character device driver typically used for remote logins.
Viva Voice:
Introduction:
Commands:
Login
Syntax: $login[username]
No Options
Purpose: Sign on to another account
Passwd
Man
Syntax: $man[options][section]entry…..
Options:- e option gives you a one line introduction to the command . Entry|
more gives the pagewise introduction to the command
Purpose: Display On – Line UNIX user’s manual.
Date
Syntax: $date[username]
No Options
Purpose: Sign on to another account
Mesg
Syntax: $mesg[option]
Options: none- Report your terminal write permission
N Remove write permission for your terminal
Y Grant write permission for your terminal
Syntax: $mail[option]
$mail username…….
Options
-p Display entire contents of mailfile without prompting for instructions,
then mail exits.
-q Cause mail to exit after receiving an interrupt signal without changing
the mailfile
-r Reverse order in which mail displays messages.
$mail username…
Type your text here….
$mail
From username fri sep 7 12:40 PDT 1984
Your text display here………..
??
q quit
x exit without changing mail.
P print
S[file] save (default mbox)
d delete
Purpose: Send or Receive electronic mail among users
Echo
Syntax: $echo[options][arg…….]
Options:- n Do not terminate output with a new line character
Purpose: Display the contents of command
tty
Syntax : $tty
No Options
Purpose: Get your terminal name
Date
Syntax: $date
$date[+format]
Format
The formatting directives for the date include
Cal
Who
Syntax: $who
Purpose: Determine who is on the system
Who am I
Syntax: $who am I
Purpose: Display the name under which you are logged in.
Viva Voice:
Introduction:
Commands:
Cd
Syntax: $cd
$cd pathname
No options
Mkdir
Rmdir
Pwd
Syntax: %pwd
No options
Aim: To study and implement all the file oriented Commands of UNIX (ls-
list files, Cat, cp, rm commands)
Introduction:
Commands:
ls
cat
$cat filename
This is used for displaying the contents of a file.
cp
rm
mv
Result:
Viva Voice:
Introduction:
Commands:
Head
tail
cat
paste
Viva Voice:
Theory:
Common Object File Format(COFF). COFF is the format of the output file
produced by the assembler and the link editor.
The object file supports user –defined sections and contains extensive
information for symbolic software testing. An object file contains:
• A File header
• Optional header information
• A table of section headers
• Data corresponding to the section headers.
• Relocation information
• Line numbers
• A symbol table
• A String table
FILE HEADER
Optional Information
Section 1 Header
…
Section n Header
Raw Data for Section 1
…..
Raw Data for Section n
Relocation Info for Sect. 1
…
Relocation Info for Sect .n
Line Numbers for Sect.1
…
Line Numbers for Sect. n
SYMBOL TABLE
STRING TABLE
Viva Voice: