Computer Organization and Design Fundamentals by David Tarnoff is now available!

Although the set of notes you have requested is presented below, it has not been maintained since January, 2001. All of the information in these notes has been included in an on-line text titled Computer Organization and Design Fundamentals. The book is available in three formats, two of which are free electronic downloads. Please visit one of the following links in order to access the format you prefer.

Thank you for your interest in this textbook. Please feel free to e-mail me at tarnoff if you have any questions or comments.

-Dave Tarnoff

Introduction to Microprocessors

Topic: Now that we've learned the architecture of the 8088, now we shall learn to program it.

Reading: Digital Fundamentals sections 14.4 and 14.5

Assembly Language Review

Last week, we went through an exercise that brought most of us a little closer to the concept of assembly language. It involved coming up with a list of possible operations we could perform on two registers, A and B.

Register A   Register B

Of course the different sections of my classes came up with different lists of operations, but some of them looked like this:

  • Move data from A to B
  • Move data from A to memory
  • Move data from memory to A
  • Move data from B to A
  • Move data from B to memory
  • Move data from memory to B
  • Add A and B and put result in A
  • Add A and B and put result in B
  • Take the 2's complement of A
  • Take the 2's complement of B
  • Clear A
  • Clear B

This was great, except that the microprocessor did not understand English. It understood binary values that were to be interpreted by the Instruction Decoder shown in the CPU block diagram repeated below from last week's notes.

So we gave each command a number. Note that the numbers below are given in hex.

Instruction description
01 Move data from A to B
02 Move data from A to memory
03 Move data from memory to A
04 Move data from B to A
05 Move data from B to memory
06 Move data from memory to B
07 Add A and B and put result in A
08 Add A and B and put result in B
09 Take the 2's complement of A
0A Take the 2's complement of B
0B Clear A
0C Clear B

Next we created a program to move data from memory address 5E0016 into register A, then from memory address 5E0116 into register B, add the two registers putting the result into register A, and store the result into memory address 5E0216. The code looked like this with the text after the semi-colon representing comments. (i.e., they are ignored for program execution.)

03    5E00    ; Move data from address 5E0016 into A
06    5E01    ; Move data from address 5E0116 into A
07            ; Add A and B and put result in A 
02    5E02    ; Move data from A to address 5E0216

In order for the computer to execute this code, it is stored in memory as a sequence of binary numbers. (No comments are stored with code.) Therefore, this program would look like the following in memory. (Numbers are represented in hex, but would be stored in binary.)

03 5E 00 06 5E 01 07 02 5E 02

Unfortunately, human beings are not very adept at programming with numbers. We prefer words that follow our linguistic nature. So for each of our commands, we made up a short word to represent the function of the machine code. This group of words is called assembly language.

Instruction description
MOVAB 01 Move data from A to B
MOVAM 02 Move data from A to memory
MOVMA 03 Move data from memory to A
MOVBA 04 Move data from B to A
MOVBM 05 Move data from B to memory
MOVMB 06 Move data from memory to B
ADDAB 07 Add A and B and put result in A
ADDBA 08 Add A and B and put result in B
CMPLA 09 Take the 2's complement of A
CMPLB 0A Take the 2's complement of B
CLRA 0B Clear A
CLRB 0C Clear B

This allowed us to convert our machine code program into an assembly language program that made a little more sense to us when we looked at it. (It's still rather cryptic though.)

MOVMA    5E00    ; Move data from address 5E0016 into A
MOVBA    5E01    ; Move data from address 5E0116 into A
ADDAB            ; Add A and B and put result in A 
MOVAM    5E02    ; Move data from A to address 5E0216

A program called an assembler takes this assembly language program and converts it to the machine code that the computer will be executing.

You, however, may be familiar with programming in a high-level language as C++ or VisualBasic. These programs are also broken down to machine code. It just takes an additional step. A compiler or interpreter is used to break the complex instructions into the "baby steps" of machine code. For example the C instruction if(B * C > 10) routine(); has multiple steps in machine code.

  1. Find address for B.
  2. Load value at address for B into register.
  3. Find address for C.
  4. Multiply value at address for C with value stored in register.
  5. Put result in register.
  6. Compare register with number 10
  7. Check processor flags to find result of compare.  If compare was greater than, then load address for routine() into address register.

Once the compiler or interpreter breaks the complex instructions into the machine code, the computer can execute the program.

Every processor has an assembly language associated with it. Since the processors have different architectures, functions, and capabilities, the languages are usually quite different. There are, however, similarities. (This is duplicated from last Monday's notes.)

There are three categories of instructions:

  • Data transfer -- passing data between different parts of the processor
    1. Register-to-Register
    2. Register-to-Memory/Port
    3. Memory/Port-to-Register
    4. Memory/Port-to-Memory/Port
  • Data manipulation
    • Math such as add, subtract, multiply, divide
    • Logic such as and, or, xor, or not
    • Bit manipulation such as shifting
  • Program control
    • Jump to a new address of the code (this includes calling subroutines)
    • Conditional statements (equivalent to if statements in a high-level language)
    • Altering processor's state

When we start programming in assembly language, you will see these instructions and watch how they work.

8088 Assembly Language

We will be programming in assembly language in the lab for the next two laboratory experiments, so it would be helpful for you to be introduced to the 8086 assembly language.

Like most programming languages, assembly language source code must follow a well-defined syntax and structure. The following is a description of the fields of an assembly language file.

Label Field -- A label is used to associate the memory address of a specific line of code or a memory location with a text string. (Remember, those humans like to see words, not numbers.) There are some rules it must follow:

  • Labels must begin in the first column with an alphabetic character
  • It must not be a reserved string (e.g., it cannot be an assembly language command)
  • Labels must not be redefined (reused)
  • Separated (delimited) from fields that come after it by a colon

Instruction or Opcode Field -- The instruction field contains the assembly language commands that the processor is supposed to follow to run a program. The command field must follow these rules:

  • Cannot be in first column!!!
  • Must be an opcode (processor instruction) or pseudo-op code (assembler instruction)

Operand field -- The operand field contains the data that the assembly language instructions use to run. This includes addresses, constants, register names, etc. There is a link to a site later in this page that describes some of the guidelines operands must follow.

Comment Field -- Last of all, we have the comment field. The ways to represent comments in assembly language differ from assembler to assembler. For most assemblers, comments begin after opcode/operand with a semi-colon. The assembler ignores everything followed by the comment character until a carriage return/line feed (CR/LF).

As we discussed in class on Monday, assembly language can be very difficult to read. It is for this reason that comments are critical to the source code documentation of an assembly file.

Specifics on 8086 Assembly Language

All processors come with a language reference, and the 8086 family is no exception. I am not going to reproduce this reference for you here, so I recommend you look at the following two section from WEBster Home Page's The Art of Assembly Language Programming by Randall Hyde. Note that they are part of a very large page. Only read the two sections I have indicated.