Microprocessor Fundamentals Course
Microprocessor Fundamentals Course
Lecture Notes
Course Syllabus:
• Computer Architecture
• Microprocessor structure and Design
• Microprocessor programming and operation
• Microprocessor based Interfacing
1
I/O Ports :
I/O devices are connected to the computer through I/O
circuits. Each of these circuits contains several register
called I/O Ports. Some are used for data while others
are used control commands. Like memory locations, the
I/O ports have address and they are connected to the bus
system. These addresses are known as I/O address and
can only be use in input (IN) or output (OUT)
instructions.
Registers:
• Data register
• Address register
• Status register
• Index register
• Segment register
2
Instruction Execution:
To understand how the CPU operates, let’s look at how
an instruction is executed. The machine instruction has
two major parts: an opcode and operands. The opcode
specifics the type of operation and operands are often
given as memory address to the data to be manipulated.
The tow operation cycles of the microprocessor are:
(Fetch - Execute cycle)
Fetch:
1. Fetch an instruction from memory
2. Decode the instruction to determine the operation
3. Fetch data from memory if necessary.
Execute:
1. Perform the operation on the data
2. Store the result in memory if needed.
3
8086 Microprocessor simplified structure
4
Internal Bus External Bus Memory
MP 8086 16 16 1 MB
MP 8088 16 8 1 MB
MP 80286 16 16 16 MB
MP 80386DX 32 32 4 GB
MP 80386 SX 16 24 16 MB
MP 80486 DX 32 32 4 GB
Pentium 32/64 32/64 4 GB
Segment Registers
5
32 bit Base & Index Registers
32 bit EU
6
HIGH BYTE (8 bit) GP REGISTERS (16 bit) LOW BYTE (8 bit)
AH AX AL
BH BX BL
CH CX CL
DH DX DL
7
Components of Flowcharts
The first step in writing a program is to draw its flowchart which expresses the logic sequence
of this program. The components of flowcharts are:
1- Input/Output units
2- Decision
3-Process
4- Start
5- Subroutines
6- Terminator
8
Ex.:
The following flowchart represents a program that reads 100 value from a port
Start
Read value
from port
ADD
Store result in
memory
Wait 30
Second
100
Samples
?
Stop
9
Finding the Right Instruction
After you get the structure of a program worked out and written down, the next step is to
determine the instruction statements required to do each part of the program. Since the
examples in this book are based on the 8088 family of microprocessors, now is a good time to
give you an overview of the instructions the 8086 has for you to use. First, however, is a hint
about how to approach these instructions. You do not usually learn a new language by
memorizing an entire dictionary of the language. A better way is to learn a few useful words
and practice putting these words together in simple sentences. You can then learn more words
as you need them to express more complex thoughts. Likewise, you should not try to
memorize all the instructions for a microprocessor at once. As an introduction, however, the
few pages here contain a list of all the 8086 instructions with a short explanation of each.
Skim through the list and pick out a dozen or so instructions that seem useful and
understandable. As a start, look for move, input, output, logical, and arithmetic instructions.
Then look through the list again to see if you can write a simple program. You can use the
instruction reference as you write programs. Here we simply list the 8086 instructions in
functional groups with single-sentence descriptions so that you can see the types of
instructions that are available to you. As you read through this section, do not expect to
understand all the instructions. When you start writing programs, you will probably use this
section to determine the type of instruction and the instruction reference to get the instruction
details you need them. After you have written a few programs, you will remember most of the
basic instruction types and will be able to simply look up an instruction in the instruction
reference to get any additional details you need.
10
DAA Decimal (BCD) adjust after addition.
SUB Subtract byte from byte or word from word.
SBB Subtract byte and carry flag from byte word and carry flag from word.
DEC Decrement specified byte or specified word by l.
NEG Negate – invert each bit of a specified byte or word and add 1 (form 2’s
complement).
CMP Compare two specified bytes or two specified word
AAS ASCII adjust after subtraction.
DAS Decimal (BCD) adjust after subtraction.
Multiplication Instructions
MUL Multiply unsigned byte by byte or unsigned word by word
IMUL Multiply signed byte by byte or signed word by word
AAM ASCII adjust after multiplication
Division Instructions
DIV Divide unsigned word by byte or unsigned double word by word
IDIV Divide signed word by byte or signed double word by word
AAD ASCII adjust before division
CBW Fill upper byte of word with copies of sign bit of lower byte
CWD Fill upper word of double word with copies of sign bit of lower word
Shift instructions:
SHL/SAL Shift bits of word or byte left, put zero(s) in LSB(s)
SHR Shift bits of word or byte right, put zero(s) in MSB(s)
SAR Shift bits of word or byte right, copy old MSB into new MSB
Rotate instructions:
ROL Rotate bits of byte or word left, MSB to LSB and to CF
ROR Rotate bits of byte or word right, LSB to MSB and to CF
RCL Rotate bits of byte or word left, MSB to CF and CF to LSB
RCR Rotate bits of byte or word right, LSB to CF and CF to MSB
11
REP An instruction prefix. Repeat following instruction until CX
=0
REPE/REPZ An instruction prefix. Repeat instruction until CX = 0 or zero
Flag ZF!=1
REPNE/REPNZ An instruction prefix. Repeat until CX = 0 or ZF = 1
MOVS/MOVSB/MOVSW Move byte or word from one string to another
COMPS/COMPSB/COMPSW Compare two string bytes or two string words
INS/INSB/INSW (80186/80188) Input string byte or word from port
OUTS/OUTSB/OUTSW (80186/80l88) output string byte or word to port
SCAS/SCASB/SCASW Scan a string. Compare a string byte with a byte in AL or a
string word with a word in AX
LODS/LODSB/LODSW load string byte into AL or string word into AX
STOS/STOSB/STOSW Store byte from AL or word from AX into string
12
Iteration control instructions:
These instructions can be used to execute a series of instructions some number of times. Here
mnemonics separated by a ”/” represent the same instruction. Use the one that best fits the
specific application.
Interrupt instructions:
INT Interrupt program execution call service procedure
INTO Interrupt program execution OF =1
IRET Return from interrupt se procedure to main program
The assembly instruction format includes Label: which defines the program line, Opcode or
mnemonic which describe the required operation, the operand which includes the data and the
comment a typical instruction is shown down
13
Assignments:
1. Draw the diagram of 8086 microprocessor structure
2. Draw the basic components of flowcharts; Input/Outputs, Decision, Process,
Subroutines and Termination
3. Draw a flowchart that reads the temperature from a sensor and sets the heater voltage
in a control system for 8 hours.
4. Describe the operations of the Following instructions MOV, ADD, AND, ROR,
CALL, RET, HLT
5. Draw and describe the flag register
14