Page 33 - DCAP210_INTRODUCTION__TO_MICROPROCESSORS
P. 33

Unit 2: Introduction to Assembly Language


            where we have to refer to a location, either because it is the target of a branch instruction or  Notes
            because it contains data that must be loaded or stored. Consequently, if we have not made any
            programming mistakes, and if we identify all the labels, we will have identified all the symbolic
            addresses used in the program.
            The above paragraph assumes that our entire program exists between our .ORIG and .END pseudo-
            ops:
            The assembler examines each instruction in sequence, and increments the LC once for each
            assembly language instruction. If the instruction examined contains a label, a symbol table entry
            is made for that label, specifying the current contents of LC as its address. The first pass terminates
            when the .END instruction is encountered. The first instruction that has a label is at line 13. Since
            it is the sixth instruction in the program and the LC at that point contains x300A, a symbol table
            entry is constructed thus:

              Symbol                               Address
              TEST                                 x300A

            The second instruction that has a label is at line 20. At this point, the LC has been incremented to
            x3018. Thus a symbol table entry is constructed, as follows:

              Symbol                               Address
              GETCHAR                              x3018

            At the conclusion of the first pass, the symbol table has the following entries:
              Symbol                               Address
              TEST                                 x300A
              GETCHAR                              x3018
              OUTPUT                               x301E

              ASCII                                x3028
              PTR                                  x302A
            The Second Pass: Generating the Machine Language Program
            The second pass consists of going through the assembly language program a second time, line by
            line, this time with the help of the symbol table. At each line, the assembly language instruction
            is translated into an LC-3b machine language instruction.
            Starting again at the top, the assembler again discards lines 01 through 09 because they contain
            only comments. Line 0A is the .ORIG pseudo-op, which the assembler uses to initialize LC to
            x3000. The assembler moves on to line 0B, and produces the machine language instruction
            0101010010100000. Then the assembler moves on to line 0C.
            This time, when the assembler gets to line 0C, it can completely assemble the instruction since it
            knows that PTR corresponds to x302A. The instruction is LEA, which has an opcode encoding of
            1110. The Destination register (DR) is R3, that is, 011.
            PCoffset is computed as follows: We know that PTR is the label for address x302A, and that the
            incremented PC is LC+2, in this case x3004. Since PTR (x302A) must be the sum of the incremented
            PC (x3004) and twice the sign-extended PCoffset (since the offset is in words and memory is
            byte-addressable), PCoffset must be x0013 by putting Address Binary.
                          In order to use the LEA instruction, it is necessary that the source of the load, in
                          this case the address whose label is PTR, is not more than +512 or –510 memory
                          locations from the LEA instruction itself.



                                             LOVELY PROFESSIONAL UNIVERSITY                                    27
   28   29   30   31   32   33   34   35   36   37   38