This is simple simulation of linker and loader in Python for which I have taken .c file as an input.
- Open files to read and create file to write local and extern parameters.
- Declare lists local and extern to store local and extern parameters.
- Read line from file and split it into words.
- if data type in words & “extern” not in words > if ele != “;”> if ele != “,” > local.append(ele+data size+address)>address=address+data size>goto 3 until EOF
- Seek file to 0
- if “extern” in words > if ele != “;”> if ele != “,” > if (data type) >x=data type size
- second_file.seek(0)
- line in second_file>words=split line
- if ele1==data_type> continue
- if ele in words>extern.append(ele+x+address)>address=address+x>break
- goto 9 until words not end
- goto 7 until EOF
- goto 6 until EOF
- write(local)
- write(extern)
- Import os
- Get status of input file
- Get size of file (fsize)
- Assign empty blocks and size of one block
- Blocks in file=fsize / size of one block
- if fsize%size != 0 > file_block++
- if empty_blocks==0>print “Memory Full”
- if empty_blocks less than file_blocks > print “Insufficient Memory”
- else > empty_blocks=empty_blocks - file_blocks > print ” Blocks used : file_blocks Available Blocks: empty_blocks”