Laboratory Assignments of System Software

Asignment 1

Write a program that takes from the user the name of a file and a "field-number", and then reads that file and for each line in that file prints on the terminal word at position "field-number". For example if there are the following lines in the specified file -

C is a programming language.
lex produces a lexical analyser

      cc is a compiler
and if the field-number specified is 4, then the output of the program is -
programming
lexical
(NULL)
compiler
[To be completed in 1 week]

This exercise should enable the student to deal with individual words in a text file.

Asignment 2

For the assembly language discussed in the theory class, write a program that reads a file containing an assembly language program, and for each statement in the assembly program it prints on the terminal the numeric opcode. Also it should build the symbol table that contains each symbol encountered in the assembly program along with the line number in which that symbol is defined. After analysing all the lines and printing the opcodes, the symbol table should be printed on the terminal.

[To be completed in 1 week]

Asignment 3

For the assembly language discussed in the theory class, create a lexical analyser using flex utility of Linux. Use this lexical analyser in a program that detects the following errors along with corresponding line numbers in input assembly language programs-

  1. Illegal characters in the program, eg. $, ^, etc.
  2. Syntax errors
  3. Use of undefined symbols
[For the lexical analyser part, first identify the tokens to be recognized, and then write the regular expressions for each. Read man pages of flex to find out details of using it.]
[To be completed in 2 week]

Asignment 4

Assume that in the assembly language discussed in the theory class, there is a statement -

DEFINE name replace-pattern
The meaning of the statement is that afterwards in the program wherever the pattern name occurs, it will be replaced by replace-pattern. For example if there is the statement DEFINE TRUE 1, then everywhere in the subsequent part in the program if there is the word TRUE, it will be replaced by 1. An input program may contain several such define statements. Write a program to implement this feature.

[This is a very simple macro pre-processor]

[To be completed in 1 week]

Asignment 5

For the assembly language discussed in the theory class, write a program that reads a file containing an assembly language program, processes the different types of statements (imperative statements, declarative statments and assembler directives) appropriately, and produces a relocation table for the program. The program should write this table in a file as binary data (i.e., non-ASCII format) as well as print this table on the terminal in readable format.

[Appropriate location counter processing is very important in this exercise. The size of each instruction is to be maintained in the mnemonic opcode table. The ideas/routines developed for the previous assignments may be used in this assignment]

[To be completed in 2 week]