Page 29 - DCAP210_INTRODUCTION__TO_MICROPROCESSORS
P. 29

Unit 2: Introduction to Assembly Language


            AGAIN ADD R3, R3, R2                                                                  Notes

            The operands to be added are obtained from register 2 and from register 3. The result is to be
            placed in register 3. We represent each of the registers 0 through 7 as R0, R2 - R7.

            The LEA instruction (line 06) requires two operands (the memory location whose address is to be
            read) and the destination register which is to contain that address after the instruction completes
            execution. We will see momentarily that memory locations will be given symbolic addresses
            called labels. In this case, the location whose address is to be read is given the label NUMBER.
            The destination into which that address is to be loaded is register 2.
            LEA R2, NUMBER
            As we discussed in class, operands can be obtained from registers, from memory, or they may be
            literal (i.e. immediate) values in the instruction. In the case of register operands, the registers are
            explicitly represented (such as R2 and R3 in line 0C). In the case of memory operands, the symbolic
            name of the memory location is explicitly represented (such as NUMBER in line 06 and SIX in
            line 08). In the case of immediate operands, the actual value is explicitly represented (such as the
            value 0 in line 0A).

            AND R3, R3; Clear R3
            It will contain the product.
            A literal value must contain a symbol identifying the representation base of the number. We use
            for decimal, x for hexadecimal, and b for binary. Sometimes there is no ambiguity, such as in the
            case 3F0A, which is a hex number. Nonetheless, we write it as x3F0A. Sometimes there is ambiguity,
            such as in the case 1000. X1000 represents the decimal number 4096, b1000 represents the decimal
            number 8, and 1000 represents the decimal number 1000.
                          1. Inside the CPU are a number of locations, called registers, which can store
                             a number.
                          2. We use for decimal, x for hexadecimal, and b for binary.

            2.1.3 Labels

            Labels are symbolic names which are used to identify memory locations that are referred to
            explicitly in the program. In LC-3b assembly language, a label consists of from one to 20
            alphanumeric characters (i.e. a capital or lower case letter of the alphabet, or a decimal digit),
            starting with a letter of the alphabet. Now, Under21, R2D2, and C3PO are all examples of possible
            LC-3b assembly language labels.
            There are two reasons for explicitly referring to a memory location:
            1. The location contains the target of a branch instruction

            2. The location contains a value that is loaded or stored.
            The location AGAIN is specifically referenced by the branch instruction in line 10.
            BRP AGAIN

            If the result of ADD R, R1 is positive (as evidenced by the P condition code being set), then the
            program branches to the location explicitly referenced as AGAIN to perform iteration.

            The location number is specifically referenced by the LEA instruction in line 06. The value stored
            in the memory location explicitly referenced as number is loaded into R2. If a location in the
            program is not explicitly referenced, then there is no need to give it a label.







                                             LOVELY PROFESSIONAL UNIVERSITY                                    23
   24   25   26   27   28   29   30   31   32   33   34