                  Microcomputer Fundamentals

Greetings from The Overlord and The Illusions BBS.  This is
the first article in a series which will deal with some of
the more technical aspects of our silicon slaves.  This first
article will lay the basic fundamentals upon which I will
build into more technical entries in the future.


                         Introduction

More than 20 companies produce a wide variety of general-
purpose microprocessors.  Even more companies assemble
microcomputers, memories and other components into
microcomputer systems.  Because of these wide variations, I
have slected a generic microprocessor for the purposes of
this discussion.  This generic microprocessor will have many
of the characteristics of common microcomputers.

When learning about a new microprocessor, the programmer must
study the following:

     - Micrprocesor Architecture
     - Instruction Set
     - Minimal System using this microprocessor
     - Control Signals
     - Pin Functions

The architecture can deal with the arrangement of registers
in the CPU, the number of bits in the address and data buses,
etc..

The instruction set is a listing of the operations the
microprocessor can perform.  This includes transferring data,
data testing and branching instructions, and input/output
operations.  These instructions use a variety of addressing
modes.

A schematic of a minimal system will show how other devices
are connected to the microprocessor.  A minimal system may
contain a microprocessor, a clock, a RAM, a ROM, input/ouput
ports, an address decoder, and a power supply.  Sometimes
these functions are performed by seperate IC's or components;
however, some microprocessor units contain most of these
capabilities.

The control signals include outputs that direct other IC's
(Such as RAMs, ROMs and I/O ports) when to operate.  Some
typical control signals might govern memory reading and
writing or input/output reading and writing.

A study of each IC pin function will further detail special
inputs and outputs of the microprocessor.  Other pins might
be power supply, clock, serial data I/O, interrupt inputs,
and bus control.


                       Instruction Set

The group of intructions that a microprocessor can execute is
called its instruction set.  Microprocessor instruction sets
may have as few as 8 or as many as 200 basic instructions.
Instructions sets are NOT standardized.  This is due to the
individualism of each manufacturer and to the differences in
architecture and intended use of microprocessors.

Instructions in an instruction set can be categorized several
ways.  Based on the IEEE proposed standard, instructions in
this discussions will be organized into the following
categories:

     1. Arithmetic Instructions
     2. Logical Instructions
     3. Data Transfer Instructions
     4. Branch Instructions
     5. Subroutine Call Instructions
     6. Return Instructions
     7. Miscellaneous Instructions

A simple instruction set would include the following
Arithmetic Instructions:

     - Add
     - Subtract
     - Increment
     - Decrement
     - Compare
     - Negate

Other arithmentic instructions used by some microprocessors
might include: Add with Carry, Subtract with carry/borrow,
multiply, and divide operations.

The same simplified microprocessor would have the following
Logical Instructions:

     - AND
     - OR
     - Exclusive OR
     - Not
     - Shift Right
     - Shift Left

Other MPUs might include: Shift Right Arithmetic, Rotate
Right, Rotate Left, Rotate Right through Carry, Rotate Left
through Carry, and the Test operation.

The basic MPU would contain the following Data Transfer
Instructions:

     - Load
     - Store
     - Move
     - Input
     - Output

Other Data Transfer instructions might include: Exchange and
various Clear and Set operations.

The MPU would contain the following Branch Instructions:

     - Unconditional Branch
     - Branch if Zero
     - Branch if Not Zero
     - Branch if Equal
     - Branch if Not Equal
     - Branch if Positive
     - Bracnch if Negative

Other Conditional Branch Instructions in an Instructions Set
might depend on conditions such as Greater than or Less than,
No Carry or Carry, No Overflow or Overflow.  The Branch
operations are the DECISION MAKING instructions.

A simple MPU would have a Subroutine Call instruction
(Referred to as CALL) to make a program jump to a special
group of instructions which perform a specific Task.  ALL
MPUs have the Unconditional Call instruction, and some have
conditional call instructions as well.  Conditional Call
instructions might include: Call if Zero, Call if Not Zero,
Call if Positive, Call If Negative, etc..

At the end of a subroutine, the program must return to where
it originally left off in the main program listing.  This
task is accomplished with a Return Instruction.  Return
instructions might include: Return from Subroutine or Return
from Interrupt operations.  Returns are usually
unconditional, but some MPUs contain condition return
instructions.

A simple MPU instruction set would include the following Misc
Instructions:

     - No Operation (NOP)
     - Push
     - Pop
     - Wait
     - Halt

Other Misc Instructions might include: Enable Inturrupt,
Diasable Interrupt, Break, and Decimal Adjust operations.

Microprocessor users encounter several ways of describing the
same instruction.  Several of these methods are diagramed
below for the ADD instruction for the Motorola 6800 MPU:

Operation    Mnemonic   Op Code(Hex)      Symbolic

  Add         ADD A         8B             A+M --> A


The name instruction is typically an action verb and is
called an operation.  In the figure above, the operation is
to ADD.  MPU users frequently with abbreviated forms of the
instruction called a Mnemonic (Note that Mnemonics are
CAPITALIZED).  The instruction register and the instruction
decoding circuitry of a microprocessor understands only 0's
and 1's.  The Op Code is the Hexadecimal representation of
the 8-bit binary code that will cause the MPU to execute the
instruction.  In the fig above, the Op Code for ADD A is
8B(Hex) or 1000 1011 (Binary) for the 6800 microprocessor.
The symbolic column shows that the contents of memory (M) are
added to the contents of Accumulator A in the MPU, with the
arrow denoting that the sum is placed in Accumulator A.  Note
that the contents of the memory location have NOT been
changed, whereas the contents of Accumulator A have been
changed and now contain the new sum.


                 Simplified CPU Organization

The primary functioning unit of any computer system is called
the Central Processing Unit or CPU.  Many microprocessor ICs
are the CPU of the system.  It is common in computer
technology to implement the program memory, data memory,
input/output interfaces, address decode, and CPU with
seperate ICs.  The MPU forms the Central Processing Unit of
such a system.

Generally, the CPU will contain storage elements called
registers and computational circuitry called the ALU
(Algorithmic and Logic Unit).  The CPU will also contain
Instruction-Decoding circuitry and a Control and Timing
Section.

The primary functions of the CPU of a microcomputer are to:

     - Fetch, Decode, and Execute program instructions in the
       proper order.

     - Transfer Data to and from memory and to and from the
       input/ouput sections.

     - Respond to External Interrupts (IE: Keyboard)

     - Provide overall Timing and Control signals for the
       entire system.

The CPU's ALU performs operations such as Add, Shift/Rotate,
Compare, Incement, Decrement, Negate, AND, OR, XOR,
Complement, Clear, and Preset.  The ALU has an Adder and
Shifter, with results being fed back into the accumulator via
the Internal Data Bus.  Of CRITICAL importance to the
programmer is the Status Register located in the ALU.  The
Status Register may also be referred to as the Condition Code
Register or the Flags.  The register is really a group of
individual Flip-Flops that can be set or reset based on the
conditions created by the last ALU operation.  The individual
flip-flops, or Flags, include indicators for Zero, Negative
results, Carry from the MSB, etc..  The flags are used for
decision making when using subsequent Branching instructions.
The Temporary and Accumulator Registers are many times
considered to be part of the ALU.  The Accumulator is
typically used in most operations performed by the CPU such
as Data Transfers.  

The Control and Timing sectio is probably the most complex section 
of the CPU.  It affects and sequences all events within the CPU and 
the entire microcomputer.  Previously, I mentioned that each program 
instruction can be divided into Fetch, Decode and Execute stages.  
Each of these stages can be further subdivided into a series of 
tiny steps that might be refered to as a Microprogram.  The 
microprogram for each instruction resides in the 
Instruction-Decoding section and is carried out by the Control and 
Timing Section of the CPU.

A 16-bit register called a Program Counter (PC) is part of the CPU.  The 
program counter is responsible for keeping track of the address of 
the next instruction to be fetched from memory.  Because program 
instructions are normally performed in sequence, the PC normally 
counts upward unless told to do otherwise.  Many common 
microprocessors have a 16-bit PC which will address 64K memory 
words via the address bus.  The normal sequential execution of 
program instructions can be altered by special Branch, Call, or 
Return instructions or Interrupts which cause the PC to jump to 
another number other than the next higher address.  To run a 
program after a power-on sequence, the computer operator must 
initially set the PC to the number of the first instruction in the 
program.

The Fetch, Decode, Execute instruction sequence is fundamental to 
computer operation.  The first instruction fetched from program 
memory is assumed to be the Op Code for the first instruction and 
is placed in the Instruction Register by the CPU Control Section.  
The Op Code is then interpreted by the Instruction Decoder.  The 
Instruction Decoder then directs the Control and Timing Section the 
microprogram is to follow to execute the specific instruction.

                      Microcomputer Operation

Consider the simple task of adding three number such as: 10+5+18=33.
A short program could be written to perform this elementary task 
using the following steps:

     - LOAD the first number (10) into the CPU Accumulator
     - ADD the second number (5) ((Contained in a memory 
       location)), to the first.
     - ADD the third number (18) ((also in a memory location))
       to the sum of the first two numbers.
     - STORE the sum of the three numbers in a data memory location.

After loading into memory the above instructions might appear like 
so:
      Address(Hex)     Contents(Hex)

        0000               86 \
                               ---> LOAD
        0001               0A /

        0002               8B \
                               ---> ADD
        0003               05 /

        0004               8B \
                               ---> ADD
        0005               12 /

        0006               B7 \
                              
        0007               20  ----> STORE

        0008               00 /           

Note that the first instruction of the program starts at address 
0000H.  The first instruction (LOAD the number 0AH) takes up two 
bytes of memory.  The first byte of memory holds the operation part 
of the instruction, while the second byte holds the operand.  The 
OpCode for the LOAD operation is given as 86H (1000 0110 Binary) 
for the microprocessor being used for this example.  The operand, 
0AH (0000 1010 Binary) is the first number to be loaded into the 
accumulator of the MPU.  Note, it is often customary to represent 
binary quantities in both the address and contents columns with 
hexadecimal notation.  In the actual machine, these are HIGH and 
LOW voltage levels.

Consider the Fetching, Decoding, and Executing of the LOAD 
instruction at address 0000H and 0001H in program memory above.  
This type of load instruction would probably be executed in about 2 
to 6 micro-seconds bt many microcomputers.

Thus concludes the first of a 10 part series delving into the guts 
of our confusers.  I know that this article may seem a bit BASIC to
most of you, but remember.. Everyone starts out from the same 
place. In future articles, I will be getting more advanced and 
technical.  Till next month.... Take OFF, Eh?

                      <<< * The Overlord * >>>

Trivia Question : Name seven possible interpretations of an 8-bit 
                  memory word.


Frost Bite: Here's where you need to figure out the prize for answering this 
            question correctly.              

