Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Introduction to Microcontrollers. Architecture, Programming, and Interfacing of the Motorola 68HC12 (G.J. Lipovski, 1999).pdf
Скачиваний:
190
Добавлен:
12.08.2013
Размер:
29.57 Mб
Скачать

2

The Instruction Set

In our study of how the computer ticks, we think that you will be motivated to read this chapter because it will describe the actions the computer can do. It will supply a key ingredient that you need to write programs, so that the computer can magnify your ideas as a lever can magnify your physical capabilities. The next chapter completes the study of the instruction set by describing the addressing modes used with these instructions.

In order to learn the possible actions or operations that a computer may execute, you need to keep a perspective. There is a lot of detail. You do need to learn this detail to be able to program the 6812. But learning about that microcomputer must be viewed as a means to an end, that is, to understand the operations of any computer in general. While you learn the details about programming the 6812, get the feel of programming by constantly relating one detail to another and questioning the reason for each instruction. When you do this, you will learn much more than the instruction set of a particular computer—you will learn about computing.

We have organized this chapter to facilitate your endeavor to compare and to associate details about different instructions and to offer some answers to questions that you might raise about these instructions. This is done by grouping similar instructions together and studying the groups one at a time, as opposed to listing instructions alphabetically or by presenting a series of examples and introducing new instructions as needed by each example as we did in Chapter 1. We group similar instructions together into a class and present each class one at a time. As mentioned in Chapter 1, the instructions for the 6812, as well as any other computer, may be classified as follows:

1.

Move instructions

2. Arithmetic instructions

3. Logic instructions

4. Edit instructions

5. Control instructions

6. Input output instructions

7.

Specialinstructions

 

 

We have added, as a separate section, the special instructions that are generally arithmetic instructions usually not used by compilers but that provide the 6812 with some unique capabilities. We now examine each instruction class for the 6812. This discussion of classes, with sections for examples and remarks, is this chapter's outline.

27

3

Addressing Modes

In the past two chapters, we have introduced the instruction cycle and the instruction set. We have used a few addressing modes in order to understand those ideas. However, we did not attempt to convey the principles of addressing modes. We now complete our understanding of the instruction by describing the addressing modes used in the 6812.

Recall from Chapter 1 that an instruction generally consists of an operation with one address in memory for an operand and/or result. How that address is determined is called addressing, and the different ways that the address is determined are called addressing modes. The data are accessed in a program, that is, read or written, by an instruction with the addressing modes available in the computer. These modes correspond to the data structures that can be easily managed in that computer. If you want to handle a particular structure, such as a string of characters, an addressing mode such as postincrement is very useful, as we discuss in more detail in Chapter 9. This chapter introduces the 6812's addressing modes, which provide the tools that make handling the most useful data structures so easy on this machine. Learning the rich set of addressing modes here will also make it easier later to learn about the common data structures.

This chapter introduces the following general aspects of addressing. We first discuss addressing modes that are determined by bits in the operation code byte, which is generally the first byte of the instruction. Indexing modes use a post byte and are discussed next. Relative modes are then discussed to show the important concept of position independence. We give examples that rework the addition program of Chapter 1 to illustrate data structure ideas and position independence using these addressing modes. Finally, we consider some architectural thoughts about addressing such as multiple address instructions and the effective address computation in the fetch execute cycle. We also discuss the level of addressing that indicates how many times an address must be read from memory to get the actual or effective address of the operand or result used with theinstruction.

Upon completion of this chapter, you should be able to use the addressing modes described here with any instruction that has been introduced in Chapter 2. You should be able to determine what has been done to compute the effective address, what that effective address will be, and what side effects are generated where some modes are used. This will prepare you to use good data structures in your programs and thus to write shorter, faster, and clearer programs as you progress through this material.

57