LIST OF
EXPERIMENTS
1. File Manipulation
2. Length
of Macro
3.
Implementation of Macro Processor
4.
Implement a Symbol Table with functions to create, insert, modify, search &
display.
5.
Implementation of Text Editor
6.
Implement Pass 1 of Two pass Assembler.
7.
Implement pass 2 of Two pass Assembler
8.
Implementation of Absolute Loader
9.
Implementation of Relocation Loader
10.
Implementation of Pass 1 of Direct-Linking Loader.
11.
Implementation of Pass 2 of Direct-Linking Loader.
Ex No 1:
FILE MANIPULATION
Aim: To write a C Program to
create an employee database & to calculate net and gross salary using
files.
Algorithm:
1. Enter name salary and deduction for employees in a text file.
2. In a C program create a structure for
employees.
3. The members are name salary &
deduction..
4. Open the files in read mode and get the
values of salary and deduction
5. Calculate the net & gross salary
6. Close the file.
7. Open a new file in write mode and write
the values of name,salary, deduction into it.
8. Print the database from the file and
close it.
Ex No :2
LENGTH OF MACRO
Aim: To create a program in
c implementing files to find the macrolength of a file.
Algorithm:
1. Create and open a file in read mode.
2. Type words between macro and mend.
3. Save the file and open it.
4. Read its content.
5. Increment the counter variable till the
string comparison is not equal to zero.
6. Decrement the counter variable once it
is equal to zero.
7. Print the counter variable which is
number of lines.
8. End.
EX NO: 3
IMPLEMENTATION OF MACRO PROCESSOR
Aim: To write a C program to
implement macro expansion.
Algorithm:
1. Get the statement from input file.
2. From the line read, check if opcode is
directive "MACRO" if so then number of macro "n" must be
incremented.
3. Repeat step 1 and 2 until end of file is
encountered.
4. Open 'n' number of files in write mode.
These files will later hold body of 'n' macro respectively.
5. Rewind the input file pointer
6. If opcode is "macro"
7. Enter macro name present in operand file
field into array named "m".
8. Write line to expanded output file.
9. Enter lines in body of each macro into
corresponding files already opened in file.
10. Write body of each macro to be expanded
output file also until "MEND" is reached.
11. Else if OPCODE is "CALL" the
line must be a macro invocation statement so the macro body is retrieved
from the corresponding file.
12. Write all the remaining lines directly
to expanded lines.
Ex No :4
SYMBOL TABLE
Aim: To Write a program in C
to implement the symbol table.
Algorithm:
1. Create a structure having member variable and values.
2. Display the options and get choice from
user.
3. If choice 1 call create.
4. If choice 2 call insert.
5. If choice 3 call modify
6. If choice 4 call search.
7. If choice 5 call display.
8. Exit.
9. Create()
1. Do till I less than 3.
2. Get input from the user for variables
and values.
1. Insert()
3. Get number of records to insert.
10.1.1 Do till i is less than sum of I and
number of recors to insert.
10.2 Get input for symbol name and value
1. Modify()
4. Get record or symbol name to modify.
5. If it is equal to any symbol name then
print record found else print record not fund.
6. Get the value for corresponding symbol
name.
1. Search()
7. Get the symbol name to modify.
8. If it is present in table then print
record found else print record not found.
1. Display()
9. Do till k is less than total number of
records.
10. Print the symbol names and values..
Ex No 5:
IMPLEMENTATION OF TEXT EDITOR
Aim: To write a C Program
fro text editor using files.
Algorithm:
1. Display options new, open and exit and
get choice.
2. If choice 1 , call new.
3. If choice 2, call open.
4. else, exit.
5. new()
11. Get the file name and open it in write
mode.
12. Get the text from the user to write it.
1. open()
13. Get the file name from user.
14. If present then open it in append mode.
15. Display options modify,search,back and
get choice.
16. If choice 1, call modify.
17. If choice 2, call search.
18. Exit
1. modify()
19. Get the text to add the existing file.
20. Write it into the file and save the
file.
1. Search()
21. Get the string to search.
22. If it is present then print word found.
23. Else, print word not found.
Ex No :6
Implement a Pass I of Two Pass Assembler
Aim: To write a C program to
perform pass1 of a two assembler.
Algorithm:
1. Start the assembly process by processing
the assembly program statements.
2. Location counter is initialized to the
starting address if OPCODE = "START" else if it is
initialized to 0.It is incremented
depending upon the size of next consecutive instruction.
3. If there is any symbol present in lable
field, location counter is entered into symbol table.The
opcode table must be present in the memory
during pass1.
4. Search the OPTAB.If it is found add 3 to
locctr.
5. If not found in OPTAB, update the
location value by checking whether the opcode is
WORD,RESW,RESB or BYTE.
6. Write the program line with locctr value
to intermediate file.
7. Read the next input line.
8. Steps3 to 7 is carried out till the end
statement is reached.
9. Finally save the value of 1
locctr-starting address) and program length.
10. Stop.
EX NO:7
IMPLEMENT PASS-2 OF TWO PASS ASSEMBLER
Aim: To write a C-program to
implement pass-2 assembler ie object code creation.
Algorithm:
1.
Read first line from the
intermediate file.
2.
Check to see if the opcode from the first line read is
"START".If so then write label,opcode and operand field values of
corresponding statement directly to final output files.
3.
start the following processing for other lines in intermediate
file if it is not a comment line until an "END" statement is reached.
4.
Start writing labels LOCCTR opcode and operand fields of
corresponding statement to the output file along with object code.The object
code is found by assembling each statement opcode machine equivalent with label
address.
5.
If there is no symbol or label in the operand field, then the
operand address is assigned as zero and it is assembled with object code of
instruction
6.
If OPCODE is BYTE,WORD,RESB etc are convert constants to oblect
code close operand file and exit.
EX NO:8
IMPLEMENTATION OF ABSOLUTE LOADER
Aim: To implement absolute loader
using C-Program.
Algorithm:
1.
Read loader record and filter the starting location and other
details.
2.
Read the first text record
3.
If the object code is in character form convert it to internal
hexadecimal representation.
4.
Move object code to specified location in memory.
5.
Write the starting location counter value of block of object
code and corresponding internal hexadecimal representation to the output file.
6.
Read next text record from the input file
7.
Close all opened files and exit.
EX NO: 9
IMPLEMENTATION OF RELOCATION LOADER
Aim: To implement relocation
loader using C- Program.
Algorithm:
1.
Enter new starting location to which object code has to be
relocated.
2.
Read the content of the input file as strings one at a time in an
array input.
3.
Transfer the string read in array "input" into another
array "output" until it is incremented.
4.
Move consecutive next 3 strings into array "output".
5.
Cover current relocation bit associated with each text record to
binary form.
6.
Make necessary changes in corresponding words of object code and
store the updated object code into array "output".
7.
Move object code for which corresponding relocation bit is not
set directly to the array "output" from array "input"
without any change.
8.
Repeat step 2 to 8 until end record is encountered.
9.
If the object code is in character from convert into internal
hexadecimal representation .
10.
Move object code to specified location in memory.
11.
write starting LOCCTR value of block of object code and the
corresponding internal hexadecimal representative to the output files.
EX NO: 10
IMPLEMENTATION OF PASS - 1 OF A DIRECT LINKING LOADER
Aim: To implement pass - 1
of a direct-linking loader
Algorithm:
1.
Get the PROGADDR from the user
2.
Initiate CSADDR with
value of PROGADDR
3.
Read header record from
object program
4.
Store the length of the
control section in CSLTH
5.
Search the ESTAB for
control section name
6.
If found display an error message
7.
Otherwise, insert the control section name with CSADDR into
ESTAB
8.
Read the next input
record
9.
If the record type is END
goto step 10
10.
If the record type is not
D goto step 6
11.
Search the ESTAB for
symbol names given in D record.
12.
If found display an error message
13.
Otherwise, insert the symbol into ESTAB with the sum of CSADDR and
indicated address and goto step 6.
14.
Add CSLTH to CSADDR.
15.
If end of file is reached, Exit. Otherwise goto step 3.
EX NO: 11 IMPLEMENTATION
OF PASS - 2 OF A DIRECT LINKING LOADER
Aim: To implement pass2 of
direct linking loader using C program.
Algorithm:
1.
Read the header record from object program.
2.
Get the CSADDR for the correct control section from ESTAB.
3.
Read next input record.
4.
If the record type is END, go to step 8.
5.
If the record type is 'T', place the object code in location
which is sum of CSADDR and specified
6.
address.
7.
If the record type is 'M' search the ESTAB for symbol table.
8.
If found add or subtract symbol value at location CSADDR +
specified
9.
Address.
10.
Otherwise display error message.
11.
Read next input record and go to step 4.
12.
If end of file is reached,Exit.Otherwise go to step1.
No comments:
Post a Comment