Page 29 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 29

6                             Chapter 1 Basic Computer Structure and the 6812


        index registers, and SP is a stack pointer; they are used in address calculations. The
        program counter, PC, is used to fetch the instruction. It is called a counter because it
        normally increments each time it is used. The condition code register (CC) has bits that
        are used to indicate results of tests that can be used in conditional branch instructions.
            At the beginning of the instruction cycle it is assumed that the program counter
        contains the address of the first byte of the instruction. As each byte of the instruction is
        fetched, the PC is incremented by 1, so that the PC always has the address of the next
        byte of the instruction to be read from memory. When the instruction cycle is completed,
        the PC then automatically contains the address of the first byte of the next instruction.
            We now look at the instruction statically as one or more memory bytes or as a line
        of a program. This discussion will introduce new concepts, but we have tried to keep the
        number down so that the examples can be discussed without your having too many terms
        to deal with. The examples will help to clarify the concepts that we introduce below.
            Each instruction in a microcomputer carries out an operation. The types of
        operations provided by a von Neumann computer can be categorized as follows:
             l.Move.               2. Arithmetic.                3. Logical.
             4. Edit.              5. Control.                   6. Input/output.
            At this time, we are interested in how instructions are stored in memory as part of a
        program and how they are executed by the 6812.
            After the instruction is fetched, the execute phase of the fetch execute cycle will
        often use an address in memory for the input data of the operation or for the location of
        the result of the operation. This location is called the effective address. The Motorola
        6812, like most microcomputers, is a one-address computer because each instruction can
        specify at most one effective address in memory. For instance, if an instruction were to
        move a word from location 100 in memory into register A, then 100 is the effective
        address. This effective address is generally determined by some bits in the instruction.
        The addressing mode specifies how the effective address is to be determined, and there are
        binary numbers in the instruction that are used to determine the address. The effective
        address is calculated at the beginning of the execute phase, just after the instruction is
        fetched and before any of the operations actually take place to execute the instruction.
            An instruction in the 6812 is stored in memory as one or more bytes. The first, and
        possibly only, byte of the instruction is generally the operation code byte. The
        operation code byte contains the operation code (opcode, for short), which specifies the
        operation to be carried out and the specification of the addressing mode. The remaining
        bytes of the instruction, if any, specify the effective address according to the given
        addressing mode. The bytes representing the instruction can be represented as a sequence
        of ones and zeros, that is, a binary number. The trouble with this is that it is hard to
        remember and to check an 8-bit or longer string of ones and zeros. To make it easier, we
        can represent the bit pattern as a hexadecimal number. A hexadecimal number will be
        prefixed by a dollar sign ($) to distinguish it from a decimal number. (For example, 193
        = $C1. If you are unfamiliar with hexadecimal numbers, see Appendix 1.) When the
        opcode, addressing modes, and constants used to determine the address are represented
        either as binary or hexadecimal numbers, we call this representation the machine code
        because it is the actual format used to store the instruction in the machine
        (microcomputer), and this format is used by the machine to determine what is to be done.
   24   25   26   27   28   29   30   31   32   33   34