Anda di halaman 1dari 7

EX. NO.

:01
IMPLEMENTATION OF SYMBOL TABLE

Aim:
To write a c program to implement a symbol table with function to create,
insert, modify, search, display and exit.

Algorithm:
Step 1: Design a menu through which we can create a symbol table and perform
operations as insert, modify, search and display.
Step 2: Create a symbol table with fields as ‘variable’ and ‘value’ using “create”
option.
Entries may be added to the table while it is created itself.
Step 3: Append new contents to the symbol table with the constraint that there is
no
duplication of entries, using “insert” option.
Step 4: Modify existing content of the table using modify option.
Step 5: Use display option to display the contents of the table.

EX. NO.:02

IMPLEMENTATION OF PASS ONE OF THE TWO PASS ASSEMBLER

Aim:
To write a c program to implement pass one of the two pass assembler by
creating symbol table and intermediate file.

Algorithm:
Step 1: Read the input line.
Step 2: Check to see if the opcode in the input line is “START”.
a. Find if there is any operand field after START, if so that indicates the
location from which the program has to be loaded in the memory, so
initialize the LOCCTR to the operand value.
b. Other wise if there is no value in the operand field the LOCCTR is set
to zero and the program starts loading from the starting address zero.

Step 3: Write the line to the intermediate file.


Step 4: Now start the following processing for the other lines in the program, if it
is not a comment line, until the opcode is “END”.
A) If there is a symbol in the label field.
i. Check the symbol table to see if has
already been stored over there. If so then
it is a duplicate symbol, the error
message should be displayed.
ii. Other wise the symbol is entered into the
SYMTAB, along with the memory
address in which it is stored.

B) If there is an opcode in the line read.


i. Search the OPTAB to see if the opcode
is present, if so increment the location
counter (LOCCTR) by three.
ii. a) If opcode is ‘WORD’, increment the
location counter by three.

b) If opcode is ‘BYTE’, increment the location counter by one.


c) If opcode is ‘RESW’, increment the location counter by the integer
equivalent of the operand value *3.
d) If opcode is ‘RESB’, increment the location counter by the integer
equivalent of the operand value.

C) Write each and every line processed to the intermediate


file along with their location counters.

Step 5: Subtract the starting address of the program from the final value of the
LOCCTR, to calculate the length of the program.
Step 6: Close all the operand files and exit.

EX. NO.: 03

IMPLEMENTATION OF PASS TWO OF A TWO PASS ASSEMBLER


Aim:
To write a c program to implement pass one of the two pass assembler by
creating symbol table and intermediate file.

Algorithm:
Step 1: Read the first line from the intermediate file.
Step 2: Check to see if the opcode from the first line read is “START”.
a. If so then write the label, opcode and operand field values of the
corresponding statement directly to the final output file.

Step 3: Start the following processing, for the other lines in the intermediate file
if it is not a comment line until an “END” statement is reached.
a. Start writing the location counter, opcode and operand fields of the
corresponding statement to the output file, along with the object code.
The object code is found by assembling each statement opcodes
machine equivalent with the label address.
b. If there is no symbol/label in the operand field, then the operand
address is assigned as zero, and it is assembled with the object code of
the instruction.
c. If the opcode is BYTE, WORD, RESB etc. convert the constants to the
object code.

Step 4: Close the operand files and exit.

EX. NO.: 04

IMPLEMENTATION OF A SINGLE PASS ASSEMBLER


Aim:
To write a c program to implement a single pass assembler
Algorithm:
Step 1: Assembler simply generates object code as it scans the source program.
Step 2: If the instruction operand is a symbol that has not yet been defined, the
operand
address is omitted when the instruction is assembled.
Step 3: This symbol entered into the symbol table, as an undefined symbol with
‘*’.
Step 4: When the definition of the symbol is encountered, the proper address is
inserted
in a list associated with that symbol.
Step 5: When nearly half of the program translation is over some of the forward
reference problems that existed earlier would have been resolved, while
others
might have been added.
Step 6: Continue the process to the end of the program to fill all the forward
reference
properly.
Step 7: At the end of the program, symbol table entries still marked with ‘*’ are
undefined symbols.

EX. NO.: 05
IMPLEMENTAION OF A SINGLE PASS MACRO PROCESSOR

Aim:
To write a c program to implement a macro processor.

Algorithm:

Step 1: Get the statement from the input file.


Step 2: From the line read, check if the opcode is the directive “MACRO”, if so
then the
number of macro ‘n’ must be incremented.
Step 3: Repeat step 1 and 2 until an end of file is encountered.
Step 4: Open ‘n’ number of files in write mode. These files will later hold the
body of
the ‘n’ macros respectively.
Step 5: Rewind the input file pointer.
Step 6: If the opcode is “macro”
a. Enter the macro name present in the operand field into the array named
‘m’.
b. Write the line to the expanded output file.
c. Enter lines in the body of each macro into the corresponding files
already opened in step 4.
d. Write the body of each macro to the expanded output file also, until a
“mend” is reached.

Step 7: Otherwise if the opcode is “call” the line must be a macro invocation
statement
so, the macro body is retrieved from the corresponding file and written to
the
expanded output file.
Step 8: Write all the remaining lines directly to the expanded lines.

EX. NO. 6
IMPLEMENTATION OF AN ABSOLUTE LOADER

Aim:
To write a c program to implement an absolute loader.

Algorithm:

Step 1: Read header record and filter the starting location and other details.
Step 2: Read first text record
Step 3: Do the following processing until an end record is reached.
a. If object code is in character form convert it to internal hexadecimal
representation.
b. Move object codes to specified locations in memory.
c. Write the starting location counter value of a block of object code and
corresponding internal hexadecimal representation to the output file.
d. Read next text record from the input file.

Step 4: Close all the open file and exit.

EX. NO. 07

IMPLEMENTAION OF A RELOCATION LOADER

Aim:
To write a c program to implement a relocation loader.
Algorithm:
Step 1: Enter the new starting location to which the object code has to be
relocated.
Step 2: Read the content of the input file as strings one at a time in array “input”.
Step 3: Transfer the string read in array “input” into another array “output” until
‘T’ is
encountered.
Step 4: Move the consecutive next three strings into array “output”.
Step 5: Convert the current string read which is relocation bit associated with
each text
record to binary form.
Step 6: Make the necessary changes in the corresponding words of object code
by
adding the new starting address with address part of the object code which
the
corresponding relocation bit is set, and store the updated object code into
the
array “output”.
Step 7: Move the object code for which the corresponding relocation bit is not set
directly to the array “output” from the array “input” without any change.
Step 8: Repeat step 2 to 8 until an end record is encountered.
Step 9: If object code is in character form converts it to internal hexadecimal
representation.
Step 10: Move object codes to specified locations in memory.
Step 11: Write the starting location counter value of a block of object code, and
corresponding internal hexadecimal representations to the output file.

EX. NO.: 08

IMPLEMENTATION OF PASS ONE OF DIRECT LINKING LOADER

Aim:
To write a c program to implement pass one of direct linking loader.

Algorithm:
Step 1: Enter the location where the program has to be loaded.
Step 2: Assign the address got from the user as the first control section address.
Step 3: Read the header record of the control section
a. From the details of the header read store the control section length in a
variable.
b. Enter the control section name with its address into the external
symbol table.
Step 4: For each symbol in the subsequence ‘D’ records the symbol must be
entered into
the symbol table along with its address, added along with the
corresponding
control section address until an end record is reached.
Step 5: Assign the starting address of next control section as the address of the
current
control section plus the length of the control section.
Step 6: Repeat the process from step 3 to 5 until there are no more inputs.

EX. NO. 09

IMPLEMENTATION OF PASS TWO OF A DIRECT LINKING LOADER

Aim:
To write a c program to implement pass two of direct linking loader.

Algorithm:
Step 1: Assign the control section address in a variable, CSADR.
Step 2: Read the header record
a. From the information available in the header record read, store the
control section length in a variable.

Step 3: Do the following process until an ‘end’ record is reached.


a. If the subsequent records read is a text record ‘T’, and if the object
code is in character form convert it into machine representation, and
move the object code from the record to the memory location control
sections address plus the specified address in the text record.
b. If subsequent record read is modification record ‘M’ then search for
the modifying symbol name in the external symbol table created by
pass one if it is found then add, or subtract corresponding symbol
address found with the value starting at the location (CSADR) plus the
specified address in the modification record.

Step 4: Add the control section length to the control sections address to find the
address of the next control section, and repeat the entire process until there is no
more input.

EX. NO.: 10
IMPLEMENTAION OF A SIMPLE TEXT EDITOR

Aim:
To write a c program to implement a simple text editor.

Algorithm:
Step 1: Provide a blank screen for the user to type the document.
Step 2: Instruct the user to enter the text using the editor.
Step 3: Display the entered character on the screen.
Step 4: Characters displayed on the screen are stored in a character array.
Step 5: Specify if the content has to be saved or not.
Step 6: If SAVE option is selected.
a. Get the data file name from the user.
b. Open the file in write mode.
c. Move the content of the character array to the file and close the file.

Step 7: If OPEN option is selected


a. Open the data file in the read mode
b. Read one character at a time from the file and move it to the character
array.
c. Repeat the above step until the end of file is reached.
d. Display the characters from the character array on the screen.

Step 8: Finally close the text editor and exit.

Anda mungkin juga menyukai