Professional Documents
Culture Documents
Micro-Notes On Microprocessors 2.0
Micro-Notes On Microprocessors 2.0
Revision
A microcontroller is a devices that has the functionalities of a microprocessor but also has on-chip
memory and i/o devices.
Microprocessors are typically used as CPUs of computers while microcontrollers are used in
embedded devices.
Each microprocessor has a fixed set of instructions in the form of binary patterns called a machine
language.
The binary instructions are given abbreviated names, called mnemonics, which form the assembly
language for a given microprocessor.
Intel was developing a programmable calculator. The original design needed 12 different chips with
hardwired logic functions. Ted Hoff suggested a general-purpose chip that could perform various
logic functions which could be activated by providing patterns of 0s and 1s. Intel coined the term
microprocessor and in 1971 released the first microprocessor as the Intel 4004.
Gordon E. Moore predicted that the number of transistors will double in integrated circuits
manufactured in every 18 months. (Moores law)
Evolution: 4004 4040 8008 8080 8085 8086 8088 80186 80188 80286
80386 80486 Pentium
2
Chapter 2
8086 Machine Organization
Overview
Intel 8086
- Designer: Stephen Paul Morse
- Released in 1979
- HMOS technology
- 40-pin DIP
- CPU clock rate = 5 MHz to 10 MHz (higher than Intel 8085)
- 16-bit ALU
- 16-bit data bus and 20-bit address bus
- Lower-order address bus and data bus multiplexed
- Better support for high-level languages than previous microprocessors
- 24 addressing modes
- Bit, byte, word, and block operations
- 8- and 16-bit signed and unsigned arithmetic in binary or decimal including multiply and
divide
- Memory segmentation
- 6-byte instruction pipeline
- Hardware-level support for program debugging
Block diagram:
Memory Structure
Memory Segmentation
Input/output Structure
Register Structure
General registers:
15 8 7 0
AX AH AL Accumulator
BX BH BL Base
CX CH CL Count
DX DH DL Data
4
Segment registers:
15 0
CS Code
DS Data
SS Stack
ES Extra
Status flags:
- Carry flag (CF)
- Auxiliary carry flag (AF)
- Parity flag (PF) set if there are even numbers of 1s in the result.
- Zero flag (ZF)
- Sign flag (SF)
- Overflow flag (OF) indicates a signed result that is out of range.
Control flags:
- Direction flag (DF) direction of string manipulation instructions.
- Interrupt-enable flag (IF) enables / disables external interrupts.
- Trap flag (TF) puts processor in a single-step mode for program debugging.
Format 1: Single-operand instruction with the operand in a 16-bit register. (Register addressing
mode)
opcode reg
Format 3: Single-operand instruction with the operand in memory. (Indirect addressing mode) (3
variants)
opcode w mod opcode m
seg Segment
00 Current extra segment
01 Current code segment
10 Current stack segment
11 Current data segment
Format 5: Single-operand instruction with the operand in memory. (Direct addressing mode)
opcode w opcode lower-order data higher-order data
0 0 1 1 0
Format 6. Two-operand instruction with both operands in registers. (Register addressing mode)
opcode d w mod reg1 reg2
1 1
mode = 11
Format 7. Two-operand instruction with one operand in a register and another in memory. (Indirect
addressing mode)
opcode d w mod reg m
Format 10. Immediate-operand instruction with one operand in memory. (Immediate addressing
mode) (2 variants)
opcode w mod opcode m lower-order data higher-order data
Format 11. Immediate-operand instruction with s field with one operand in a register. (Immediate
addressing mode) (2 variants)
Sign-extend field (s)
If s = 0: 16-bit immediate operand
If s = 1: 8-bit immediate operand
Applicable only if w = 1.
7
Format 12. Immediate-operand instruction with one operand in memory. (Immediate addressing
mode) (2 variants)
opcode s w mod opcode m lower-order data higher-order data
1 1 1
mode = 00, 01, 10
higher-order data present only if s = 0
Chapter 3
8086 Instruction Set
Overview
Several instructions have a general (long) form as well as a restricted (short) form.
The short form
- uses fewer bytes
- less options for choosing operands
- used for frequently used cases
Programmer need not worry, assembler will choose proper form.
Instructions
- data transfer instructions
- general-purpose transfers
- accumulator-specific transfers
- address-object transfers
- flag transfers
- arithmetic instructions
- addition
- subtraction
- multiplication
- division
- formatting
- logical instructions
- Boolean
- shift and rotate
- string instructions
- elementary
- complex
- transfer of control instructions
- unconditional transfer
- conditional transfer
- interrupt instructions
- flag instructions
- synchronization instructions
- synchronization with subordinate processors
- resource sharing
General-purpose transfers
MOV
9
PUSH
Used for a word.
Push register/memory.
11111111 mod 110 r/m
Push register.
01010 reg
POP
Used for a word.
Pop register/memory.
10001111 mod 000 r/m
Pop register.
01011 reg
XCHG
Accumulator-specific transfers
IN
Input to AL/AX.
1110010 w port
Direct addressing mode.
Can access only the first 256 ports.
Input to AL/AX.
1110110 w
Indirect addressing mode.
Use DX as port address.
Can access only all 216 ports.
OUT
XLAT (Translate)
Transfer a byte from a table to AL.
Base of table stored in BX and index in AL originally.
Implied addressing mode.
Address-object transfers
Flag transfers
Arithmetic Instructions
Add and subtract instructions set CF if the result, as interpreted as a unsigned number, is out of
range.
Add and subtract instructions set OF if the result, as interpreted as a signed number, is out of range.
Addition
ADD
INC
12
Increment register/memory.
1111111 w mod 000 r/m
Increment register.
01000 reg
Subtraction
SUB
DEC
NEG
Negate register/memory.
1111011 w mod 011 r/m
CMP (Compare)
Similar to SUB except the operands are not affected.
Multiplication
8-bit 16-bit
Multiplicand AL AX
Multiplier Operand Operand
Product AX DX AX
MUL
Unsigned multiply.
1111011 w mod 100 r/m
IMUL
Signed multiply.
1111011 w mod 101 r/m
13
Division
8-bit 16-bit
Dividend AX DX AX
Divisor Operand Operand
Quotient AL AX
Remainder AH DX
DIV
Unsigned divide.
1111011 w mod 110 r/m
IDIV
Signed divide.
1111011 w mod 111 r/m
Formatting
Logical Instructions
Boolean
NOT
AND
OR
XOR
TEST
14
String Instructions
Elementary
1111001 w
REP (Repeat)
Complex
11100011 Difference
Difference is a signed number.
LOOP
Decrements CX and then jump.
11100010 Difference
LOOPNZ/LOOPNE
1110000 z Difference
LOOPZ/LOOPE
16
Unconditional transfer
JMP
CALL
RET
Return intra-segment.
11000011
Return inter-segment.
11001011
Conditional transfer
JE/JZ
JNE/JNZ
JL/JNGE (SF xor OF) = 1
JNL/JGE (SF xor OF) = 0
JLE/JNG ((SF xor OF) xor ZF)= 1
JNLE/JG ((SF xor OF) xor ZF)= 0
JB/JNAE CF = 1
JNB/JAE CF = 0
JBE/JNA (CF xor ZF) = 1
JNBE/JA (CF xor ZF) = 0
JP/JPE
JNP/JPO
JO
JNO
JS
JNS
Interrupt Instructions
INT
Interrupt of type 3.
11001100
Used to set breakpoints in a software debugger.
HLT
HLT stops processing and leaves CS and IP pointing to the instruction following HLT.
Flag Instructions
Synchronization Instructions
Subordinate processors
ESC (Escape)
Seek help of a subordinate processor.
WAIT
Waits for subordinate processor to complete processing.
When subordinate processor completes it send a signal to the TEST pin.
WAIT should precede ESC.
Resource sharing