Page 65 - DCAP507_SYSTEM_SOFTWARE
P. 65

Unit 4: Design of Assembler




          address for VAL1. The same thing occurs with the STORE instruction. The DATA instruction is a  Notes
          directive asking the  assembler to  describe  some  data;  for  VAL1  we  are to  generate a  '4'.
          We know that this word will be stored at relative location C, since the location counter now has
          the value  C, having been incremented by the length of each previous  instruction. The  first
          instruction, 4 bytes long (1 word), is at relative address 0. The next two instructions are also 4
          bytes long. We say that the symbol "VAL1" has the address C. The next instruction has as a label
          VAL2 and an connected location counter address 10. The label on RES has an connected address
          of 14.
          As the assembler, we can now go back via the program and fill in the missing information in the
          third column. Since symbols can emerge before they are  defined, it  is suitable  to make two
          passes over the input (as this example displays). The first pass has only to define the symbols,
          allocate addresses, and carry out syntax checking; the second pass can then produce the instructions
          and addresses. Particularly the assembler does the following:
          1.   Computes the Location Counter (Pass 1)
          2.   Scans for errors (Pass 1)

          3.   Produce instructions:
               (a)  Evaluate the mnemonic in the operation field to produce its machine code. (Pass 1)
               (b)  Evaluate the sub fields-find the value of every symbol, process literals, and assign
                    addresses. (Pass 1 & 2)
          4.   Process pseudo-ops/directives (Pass 1 & 2)

          We can group these tasks into two passes or sequential scans over the input; connected with each
          task are one or more assembler modules.

          Pass 1: Purpose-define Symbols and Literals, and Determine the Location Counter

          1.   Syntax scan
          2.   Find out length of machine instructions (Machine_Operations_Table)
          3.   Maintain track of Location Counter (Location_Counter)
          4.   Produce Symbol Table with address/value of symbols (Symbol_Table)
          5.   Memorize literals (Literal_Table came be combined with the Symbol_Table)
          6.   Process some Directives, e.g., EQU, BEGIN/ORIGIN/Start/PGM
          7.   Construct an intermediate version (file or structure) to assist pass 2
          8.   Produce data for DATA/num, SKIP, and literals (DATA_GEN).

          Pass 2: Purpose-generate Object Program

          1.   Observe addresses of symbols (Symbol_Table)
          2.   Produce instructions (Machine_Operations_Table)
          3.   Produce reports for the user
          4.   Produce the object file intended for the linker and then on to the simulator.
          4.1.3 Data Structure

          The next step in our design process is to institute the databases internal and external. We know
          for instance we will need a technique to import in the instructions, the bit equivalence, and a flag
          to specify the format of the operand field. A similar technique is required for directives. Internally
          we will require a symbol table.


                                           LOVELY PROFESSIONAL UNIVERSITY                                   59
   60   61   62   63   64   65   66   67   68   69   70