Question
You are to implement a two-pass linker in C, C++, or Java and submit the source code on NYU Classes, which we compile and run.
You are to implement a two-pass linker in C, C++, or Java and submit the source code on NYU Classes, which we compile
and run.
The target machine is word addressable and has a memory of 300 words, each consisting of 4 decimal digits. The first (leftmost) digit is the opcode, which is unchanged by the linker. The remaining three digits (called the address field) form either
An immediate operand, which is unchanged. An absolute address, which is unchanged. A relative address, which is relocated. An external address, which is resolved.
Relocating relative addresses and resolving external references were discussed in class and are in the notes.
The input consists of a series of object modules, each of which contains three parts: definition list, use list, and program text. Preceding all the object modules is a single integer giving the number of modules present.
The linker processes the input twice (that is why it is called two-pass). Pass one determines the base address for each module and the absolute address for each external symbol, storing the later in the symbol table it produces. The first module has base address zero; the base address for module I + 1 is equal to the base address of module I plus the length of module I. The absolute address for a symbol S defined in module M is the base address of M plus the relative address of S within M. Pass two uses the base addresses and the symbol table computed in pass one to generate the actual output by relocating relative addresses and resolving external references.
The definition list is a count ND (Number of Definitions) followed by ND pairs (S, R) where S is the symbol being defined and R is the relative address to which the symbol refers. Pass one relocates R forming the absolute address A and stores the pair (S, A) in the symbol table.
The use list is a count NU (Number of Uses) followed by NU pairs (S, R), where S is an external symbol used in the module and R is a relative address where S is used. The (dummy) address initially in R is a pointer to the next use of S. This linked list of uses ends with a pointer of 777.
The program text consists of a count NT (Number of Text entries) followed by NT pairs (type, word), where word is a 4-digit instruction as described above and type is a single character indicating if the address in word is Immediate, Absolute, Relative, or External. NT is also the length of the module.
Other requirements: Error detection, arbitrary limits, et al.
Your program must check the input for the errors listed below. All error messages produced must be informative, e.g., Error: X21 was used but not defined. It has been given the value 111.
-
If a symbol is multiply defined, print an error message and use the value given in the last definition.
-
If a symbol is used but not defined, print an error message and use the value 111.
-
If a symbol is defined but not used, print a warning message.
-
If an absolute address exceeds the size of the machine, print an error message and use the largest legal value.
-
If multiple symbols are listed as used in the same instruction, print an error message and ignore all but the last usage
given.
-
If a type R address in the list of Text entries exceeds the size of the module, treat the address as 0 (and relocate it
since it is an R type address).
You may need to set arbitrary limits, for example you may wish to limit the number of characters in a symbol to (say) 8. Any such limits should be clearly documented in the program and if the input fails to meet your limits, your program must print an error message. Naturally, any such limits must be large enough for all the inputs on the web. Under no circumstances should your program reference an array out of bounds, etc.
Submit the source code for your lab, together with a README file (required) describing how to compile and run it. Your program must read an input set from standard input, i.e., directly from the keyboard. It is an error for you to require the input be in a file.
You may develop your lab on any machine you wish, but must insure that it compiles and runs on the NYU system assigned to the course.
OS-202 2018-19 Spring Lab 1Linker Page 2
There are several sample input sets on the web. The first is shown below and the second is an re-formatted version of the first. If you use the java Scanner or Cs scanf() (which I recommend you do), inputs 1 and 2 will look the same to your program. Some of the input sets contain errors that you are to detect as described above. We will run your lab on these (and other) input sets. The expected output is also on the web. Please let me know right away if you think any of the outputs are wrong.
4 1 xy 2 2 xy 4 z 2 5R1004 I5678 0 1z3 6R8001 E1777 0 1z1 2 R 5001 E 4777 1z2 1 xy 2 3A8000 E1777
E2777 R8002 E7777
E1001 E3002 R1002 A1010
E2001
The following is output annotated for clarity and class discussion. Your output is not expected to be this fancy.
Symbol Table xy=2 z=15
+0 0: 1: 2: xy: 3:
4: +5 0 1 2 3 4 5 +11 0
1 +13 0 1 2 z:
Memory Map
R 1004 I 5678 E 2777 ->z R 8002 E 7002 ->xy
R 8001 E 1777 ->z E 1001 ->z E 3002 ->z R 1002 A 1010
R 5001 E 4777 ->z
A 8000 E 1777 ->xy E 2001 ->xy
1004+0 = 1004 5678 2015 8002+0 = 8002 7002
8001+5 = 8006 1015 1015 3015 1002+5 = 1007 1010
5001+11= 5012 4015
8000 1002 2002
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started