Professional Documents
Culture Documents
MP PPT 2016 171
MP PPT 2016 171
MP PPT 2016 171
Subject code:15EC42
It is a 16-bit μp.
8086 has a 20 bit address bus can access up to 220
memory locations (1 MB).
It can support up to 64K I/O ports.
It provides 14, 16 -bit registers.
Word size is 16 bits.
It has multiplexed address and data bus AD0-
AD15 and A16 – A19.
It requires single phase clock with 33% duty cycle
to provide internal timing.
Dept. of ECE, ATMECE, MYSURU 2
8086 is designed to operate in two modes, Minimum
and Maximum.
8 bits 8 bits
AH AL Accumulator
AX
BX
BH BL Base
CX CH CL Count
DX DH DL
Data
SP Stack Pointer
Pointer
BP Base Pointer
SI Source Index
Index
DI Destination Index
Dept. of ECE, ATMECE, MYSURU 8
EXECUTION UNIT – General Purpose Registers
Register Purpose
AX Word multiply, word divide, word I /O
AL Byte multiply, byte divide, byte I/O, decimal arithmetic
U U U U OF DF IF TF SF ZF U AF U PF U CF
U - Unused
Dept. of ECE, ATMECE, MYSURU 12
EXECUTION UNIT – Flag Register
Flag Purpose
Carry (CF) Holds the carry after addition or the borrow after subtraction.
Also indicates some error conditions, as dictated by some
programs and procedures .
Auxiliary (AF) Holds the carry (half – carry) after addition or borrow after
subtraction between bit positions 3 and 4 of the result
(for example, in BCD addition or subtraction.)
Zero (ZF) Shows the result of the arithmetic or logic operation.
Z=1; result is zero. Z=0; The result is 0
Sign (SF) Holds the signDept.
of ofthe result after an arithmetic/logic instruction
ECE, ATMECE, MYSURU 13
Flag Purpose
A control flag.
Trap (TF) Enables the trapping through an on-chip debugging
feature.
A control flag.
Interrupt (IF) Controls the operation of the INTR (interrupt request)
I=0; INTR pin disabled. I=1; INTR pin enabled.
A control flag.
Direction (DF) It selects either the increment or decrement mode for DI
and /or SI registers during the string instructions.
Overflow occurs when signed numbers are added or
Overflow (OF) subtracted. An overflow indicates the result has exceeded
the capacity of the Machine
1 MB
1Mbyte of memory.
Extra segment (64KB)
The Complete physically available
memory may be divided into a Stack segment (64KB)
number of logical segments.
FFFFF
BIU
Segment Registers 34BA0
CODE (64k)
44B9F
CSR 34BA
44EB0
DATA (64K)
1 MB
DSR 44EB 54EAF
54EB0
ESR 54EB EXTRA (64K)
64EAF
SSR 695E 695E0
STACK (64K)
795DF
34BA0(CS)+
8AB4(IP)
3 D 6 5 4 (next address)
44B9F
Segment Address
0001 0000 0000 0000 0000
• CS:IP
• SS:SP SS:BP
• DS:BX DS:SI
EU BIU
AX AH AL
IP
BX BH BL
Fetch &
CX CH CL D
store code CS DS ES SS
E
DX DH DL C
bytes in
C
O PIPELINE C
O PIPELINE O IP BX DI SP
D
SP D E (or) D DI BP
E O QUEUE E
BP I SI
R U
SI T N
DI
Default Assignment
Timing
FLAGS ALU control
Segment register
• Segment register is DS or SS
• E.g. MOV AX, 4[BX]
• E.G. PUSH CX
• Segment register is DS
• E.g. MOV AX, 4[SI]
• Segment register is DS
• E.g. MOV AX, 4[BX][SI]
Register Direct bit (D) occupies one bit. It defines whether the
register operand in byte 2 is the source or destination operand.
D=1 Specifies that the register operand is the destination operand.
D=0 indicates that the register is a source operand.
Data size bit (W) defines whether the operation to be performed is an
8 bit or 16 bit data
The R/M field occupies 3 bits. The R/M field along with the MOD field defines the
second operand as shown below.
MOD 11
MOD selects memory mode, then R/M indicates how the effective address of the memory
operand is to be calculated. Bytes 3 through 6 of an instruction are optional fields that
normally contain the displacement value of a memory operand and / or the actual value
of an immediate constant operand.
Dept. of ECE, ATMECE, MYSURU 51
Obtain the opcodes for the following instructions.
The 6 bit Opcode for this instruction is 1000102 D bit indicates whether the register
specified by the REG field of byte 2 is a source or destination operand.
Byte 1 Byte2
= 88DDH
To specify DS register, the SOP byte would be 001 11 110 = 3E H. Thus the 5 byte code
for this instruction would be 3E 89 96 45 23 H.
Suppose we want to code MOV SS : 2345 (BP), DX. This generates only a 4 byte code,
without SOP byte, as SS is already the default segment register in this case.
Dept. of ECE, ATMECE, MYSURU 54
Example 5:
Give the instruction template and generate code for the instruction ADD 0FABE [BX]
[DI], DX (code for ADD instruction is 000000)
ADD 0FABE [BX] [DI], DX
Here we have to specify DX using REG field. The bit D is 0, indicating that DX is the
source register. The REG field must be 010 to indicate DX register. The w must be 1 to
indicate it is a word operation. FABE (BX + DI) is specified using MOD value of 10 and
R/M value of 001 (from the summary table). The 4 byte code for this instruction would be
Example 6 :
Give the instruction template and generate the code for the instruction MOV AX, [BX]
(Code for MOV instruction is 100010)
AX destination register with D=1 and code for AX is 000 [BX] is specified using 00 Mode
and R/M value 111. It is a word operation
OUT port, acc : Out transfers a byte or a word from the AL register or the AX register
respectively to an output port. The port numbers may be specified either with an immediate
byte or with a number previously placed in the register DX allowing variable access.
POP Des:
It pops the operand from top of stack to Des.
Des can be a general purpose register, segment register
(except CS) or memory location.
E.g.: POP AX
Dept. of ECE, ATMECE, MYSURU 80
Data Transfer Instructions
• XCHG Des, Src:
– This instruction exchanges Src with Des.
– It cannot exchange two memory locations directly.
– E.g.: XCHG DX, AX
• SAHF:
– It copies the contents of AH to lower byte of flag register.
• PUSHF:
– Pushes flag register to top of stack.
• POPF:
– Pops the stack top to flag register.
• IDIV Src:
– It is a signed division instruction.
• SCAS String:
– It scans a string.
– It compares the String with byte in AL or with
word in AX.
Dept. of ECE, ATMECE, MYSURU 115
String Instructions
• MOVS / MOVSB / MOVSW:
– It causes moving of byte or word from one string
to another.
– In this instruction, the source string is in Data
Segment and destination string is in Extra
Segment.
– SI and DI store the offset values for source and
destination index.
• CLC:
– It clears the carry flag to 0.
• CMC:
– It complements the carry flag.
Dept. of ECE, ATMECE, MYSURU 119
Processor Control Instructions
• STD:
– It sets the direction flag to 1.
– If it is set, string bytes are accessed from higher
memory address to lower memory address.
• CLD:
– It clears the direction flag to 0.
– If it is reset, the string bytes are accessed from lower
memory address to higher memory address.
Dept. of ECE, ATMECE, MYSURU 120
Stack and Subroutines
The Stack
• The stack is an area of memory identified by the programmer
for temporary storage of information.
• The stack is a LIFO structure.
• – Last In First Out.
• The stack normally grows backwards into memory.
– In other words, the programmer defines the
bottom of the stack and the stack grows up
into reducing address range.
• The 8085 provides two instructions: PUSH and POP for storing
information on the stack and retrieving it back.
– Both PUSH and POP work with register pairs ONLY.
Dept. of ECE, ATMECE, MYSURU 122
The PUSH Instruction
• PUSH B (1 Byte Instruction)
– Decrement SP
– Copy the contents of register B to the memory location pointed to by
SP
– Decrement SP
– Copy the contents of register C to the memory location pointed to by
SP
B C
12 F3
FFFB
FFFC
FFFD F3
FFFE
12
FFFF SP
LIFO
• The order of PUSHs and POPs must be opposite of each other in order to retrieve
information back into its original location.
PUSH B
PUSH D
... • Reversing the order of the POP instructions will result in
POP D the exchange of the contents of BC and DE.
POP B
Dept. of ECE, ATMECE, MYSURU 125
The PSW Register Pair
• The 8085 recognizes one additional register pair
called the PSW (Program Status Word).
– This register pair is made up of the Accumulator
and the Flags registers.
PC 2 0 03
FFFB
FFFC
FFFD 03
FFFE
FFFF
20 SP
PC 2 0 03
FFFB
4014 ... FFFC
4015 RET FFFD 03 SP
FFFE
FFFF
20
• The RET instruction takes the contents of the two memory locations at
the top of the stack and uses these as the return address.
– Do not modify the stack pointer in a subroutine.
You will loose the return address.
When you are studying then your cell phone rings – what will you do?
When you finish talking on the phone then you will continue with
your study
Now your phone rings again and someone also knocking at your door
then what will you do?
After executing ISR, IRET returns the control back again to the
main program. Interrupt processing is an alternative to polling.
Dept. of ECE, ATMECE, MYSURU 141
Need for Interrupt:
Interrupts are particularly useful when interfacing
I/O devices, that provide or require data at
relatively low data transfer rate.
Sources of Interrupts:
Three types of interrupts sources are there:
1. An external signal applied to NMI or INTR input pin( hardware
interrupt)
2. Execution of Interrupt instruction( software interrupt)
3. Interrupt raised due to some error condition produced in 8086
instruction execution process. ( divide by zero, overflow errors
etc) Dept. of ECE, ATMECE, MYSURU 142
Use of interrupt
How to get key typed in the keyboard or a keypad?
Polling :-
The CPU executes a program that check for the available of
data If a key is pressed then read the data, otherwise keep waiting
or looping!!!
Interrupt:-
The CPU executes other program, as soon as a key is pressed,
the Keyboard generates an interrupt. The CPU will response to the
interrupt – read the data. After that returns to the original program.
So by proper use of interrupt, the CPU can serve many devices at the
“same time”
Dept. of ECE, ATMECE, MYSURU 143
Polling Vs Interrupt
The keyboard controller can hold only a single keystroke.
Therefore, the keyboard controller must be freed before the next
keystroke arrives.
The keystroke is passed to the CPU by putting it in the
keyboard buffer. So, the keyboard controller keeps on passing the
keystroke input to the CPU,
No Dept.
keystroke for CPU
of ECE, ATMECE, MYSURU 147
Interrupt-based systems
Interrupt-based approach
The CPU executes other program, as soon as a key is
pressed, the Keyboard generates an interrupt. The CPU
will response to the interrupt – read the data. After
that returns to the original program. So by proper use
of interrupt, the CPU can serve many devices at the
“same time” Dept. of ECE, ATMECE, MYSURU 148
Example of interrupt
Interrupt
Keeping moving until interrupted by the sensor
Move forward
Move forward
Check sensor
Y
NMI(INT2)
INTR
(iv) Find the number of clock states required for execution of each of the instructions in the time-delay
program. Then find the number of clock states (m) needed to execute the loop in the delay program
once, by adding the clock states required for each instruction in the delay program.
(v) Find the number of times (i.e., count n) the loop in the delay program has to be executed by dividing
the required time delay (td) by the time taken to execute the loop once, which is m X T
Count (n) = td/ (m X T)
The time delay obtained using this method is sufficiently accurate to be used in many problems. When
more accurate delays are required, the programmable timer IC 8253 or the 8254 can be used.
In this program, the instructions DEC BX, NOP, and JNZ L1 form the loop
as they are executed repeatedly until BX becomes zero. Once BX
becomes zero, the 8086 returns to the main program.
By loading DF37h in BX, the time taken to execute the delay program is
approximately 120ms. The NOP included in the delay program is to
increase the execution time of the loop. To get more delay, the number of
NOP instructions in the delay loop can be increased. The exact delay
obtained using this time delay subroutine can be calculated as shown in
the next slide.
• While performing these operations, the assembler may find syntax errors. They
are reported to the programmer at the end of the assembly process. The logical
and other programming errors are not found by the assembler.
• For completing these tasks the assembler needs some commands from the
programmer – the required storage class for a particular constant or a variable
such as byte, word, or double word, the logical name of the segments such as
CODE, STACK, or DATA, the type of procedures or routines such as FAR,
NEAR, PUBLIC, or EXTRN, the end of a segment etc.
• These types of commands are given to the assembler using a predefined
alphabetical strings called Assembler directives.
• Assembler directives are directions for the assembler, and not the instructions for
the 8086.
Dept. of ECE, ATMECE, MYSURU 237
Assembler Directives for variable and Constant
Definition
The Assembler directives for variable and constant definition are as follows:
(i) DB, DW, DD, DQ, and DT: the directives DB (define byte), DW(define word),
DD(define double word), DQ (define quad word), and DT (define ten bytes) are used to
reserve one byte, one word (i.e. 2 bytes), one double word(i.e. 2 words), one quad
word(i.e. 4 words) and ten bytes in memory, respectively for storing constants,
variables, or strings.
DATA 1 DB 20h ; Reserve one byte for storing
; DATA1 and assign the value 20h
; to it.
ARRAY DB 10h, 20h, 30h ; Reserve three bytes for storing ARRAY1 and
initialize it with the values
; 10h, 20h and 30h
CITY DB “NARELA” ;Store the ASCII code of the characters
; specified within double quotes in the
; array or a list named CITY
DATA2 DW 1020h ; Reserve one word for storing ;DATA2 and Assign
the value 1020 ;to it.
Dept. of ECE, ATMECE, MYSURU 238
Assembler Directives for variable and Constant
Definition
The directive DUP (duplicate) is used to reserve a series of bytes, words, double words, or ten
bytes and is used with DB, DW, DD and DT, respectively. The reserved area can be either filled
with a specific value or left uninitialized.
Example:
Array DB 20 DUP(0) ;Reserve 20 bytes in the memory
; for the array named ARRAY and
; initialize all the elements of the
; array to 0 (due to presence of 0
; within the bracket near the DUP
; directive
ARRAY1 DB 25 DUP (?) ; Reserve 25 bytes in the memory
; for the array named ARRAY1 and
; keep all the elements of the array
; uninitialized (due to the question
; mark present within the bracket near the DUP
directive)
ARRAY2 DB 50 DUP (64h) ; Reserves 50 bytes in the memory
; for the array named ARRAY2 and
; initializes all the elements of the
; array to 64h
Dept. of ECE, ATMECE, MYSURU 239
Assembler Directives for variable and Constant
Definition
(ii) EQU: The directive EQU(equivalent) is used to assign a
value to a data name.
Example:
Example:
MOV CX, LENGTH ARRAY
CX is loaded with the number of bytes in the ARRAY.
Example:
MOV BX, OFFSET TABLE
If the data item named TABLE is present in the data segment,
this statement places the offset address of TABLE, in the BX
register.
Dept. of ECE, ATMECE, MYSURU 244
Assembler Directives Related to
Code(Program) Location
The Assembler directives related to Code location:
(v) LABEL: The LABEL directive is used to assign a name to the
current value in the location counter. It is used to specify the
destination of the branch-related instructions such as jump and
call. When LABEL is used to specify the destination, it is
necessary to specify whether it is NEAR or FAR. When the
destination is in the same segment, the label is specified as
NEAR and when the destination is in another segment, it is
specified as FAR.
Example:
The second statement reserves 100 words in the stack segment and fills them with 0. The third statement assigns
the name STACK_TOP to the location present just after the hundredth word. The offset address of this label can
then be assigned to the stack pointer in the code segment using the following statement:
MOV SP, OFFSET STACK_TOP
CODE 1 SEGMENT
…… ; Instructions of CODE 1 segment
CODE 1 ENDS
This example indicates the declaration of a code segment
named CODE 1.
MOV AX, SEG ARRAY1 ; Load the segment address in which ARRAY1
is present, in AX
MOV DS, AX ; Move the contents of AX to DS.
MODULE2 SEGMENT
EXTRN SQUARE_ROOT FAR
…… ; CODE OF MODULE2
CALL SQUARE_ROOT
……
MODULE 2 ENDS
NOTE: If one wants to call the procedure named SQUARE_ROOT appearing in MODULE1 from
MODULE2, it must be declared using the statement PUBLIC SQUARE_ROOT in MODULE1 and it must be
declared external using the statement EXTRN SQUARE_ROOT in MODULE2. If a jump or a call address is
external, it must be represented as NEAR or FAR. If data are defined as external, their size must be
represented as BYTE, WORD, or DWORD.
MODULE2 SEGMENT
EXTRN SQUARE_ROOT FAR
…… ; CODE OF MODULE2
CALL SQUARE_ROOT
……
MODULE 2 ENDS
NOTE: If one wants to call the procedure named SQUARE_ROOT appearing in MODULE1
from MODULE2, it must be declared using the statement PUBLIC SQUARE_ROOT in MODULE1
and it must be declared external using the statement EXTRN SQUARE_ROOT in MODULE2. If a
jump or a call address is external, it must be represented as NEAR or FAR. If data are defined
as external, their size must be represented as BYTE,
Dept. of ECE, ATMECE, WORD, or DWORD.
MYSURU 255
Other Assembler Directives
PTR The PTR(pointer) operator is used to declare the type of label,
variable, or memory operand.
Examples: INC BYTE PTR[SI]
;Increment the byte contents of the memory location addressed
by SI
INC WORD PTR [BX]
;Increment the word contents of the memory location addressed
by BX
GLOBAL The labels, variables, constants, or procedures declared GLOBAL
may be used by other modules of the program.
Example: GLOBAL DATA1, DATA2, ARRAY1
; above statement declares the variables DATA1,
; DATA2, and ARRAY1 as GLOBAL variables
LOCAL The label, variables, constants, or procedures declared LOCAL in a
module are to be used only by that particular module.
Example: LOCAL DATA1, DATA2, ARRAY1, A1, A2
Dept. of ECE, ATMECE, MYSURU 256
Other Assembler Directives
NAME The NAME directive is used to assign a name to an assembly
language program module. The module may now be referred to by
its declared name. The names, if selected properly, may indicate
the function of the different modules, and hence help in good
documentation.
SHORT The SHORT operator indicates to the assembler the only one byte
is required to code the displacement for a jump (i.e. the
displacement is within -128 to +127 bytes from the address of the
byte present next to the JMP instruction)
TYPE The TYPE operator directs the assembler to decide the data type
of the specified label and replaces the TYPE label with the decided
data type. For the word type variable, the data type is 2. For the
double word type, its 4, and for the byte type its 1.
; Defining a MACRO
CALCULATE MACRO
MOV AX, [BX]
ADD AX, [BX + 2]
MOV [SI], AX
ENDM
; CALCULATE is the macro name and the macro is used to add two successive data in the
memory, whose offset address is present in BX and the result is stored in the memory at
the offset address in SI.
DEEPAK.P
271
Dept. of ECE, ATMECE, MYSURU 271
Memory Organization
• The address space is physically connected to a
16 -bit data bus by dividing the address space
into two 8 bit banks of up to 512K bytes each.
• One bank is connected to the lower half of the
16 bit data bus (D0-D7 ) and contains even
address bytes.
278
Dept. of ECE, ATMECE, MYSURU
Minimum Mode 8086 System
The microprocessor 8086 is operated in minimum mode by
strapping its MN/MX pin to logic 1.
In this mode, all the control signals are given out by the
microprocessor chip itself. There is a single microprocessor in
the minimum mode system.
The remaining components in the system are latches,
transreceivers, clock generator, memory and I/O devices.
The DEN signal indicates the direction of data, i.e. from or to the
processor.
The system contains memory for the monitor and users program
storage. Usually, EPROM are used for monitor storage, while RAM for
users program storage. A system may contain I/O devices.
The opcode fetch and read cycles are similar. Hence the timing diagram
can be categorized in two parts, the first is the timing diagram for read
cycle and the second is the timing diagram for write cycle.
The read cycle begins in T1 with the assertion of address latch enable
(ALE) signal and also M / IO signal. During the negative going edge of
this signal, the valid address is latched on the local bus.
At T2, the address is removed from the local bus and is sent to
the output. The bus is then tristated. The read (RD) control
signal is also activated in T2.
The read (RD) signal causes the address device to enable its data
bus drivers. After RD goes low, the valid data is available on the
data bus.
The addressed device will drive the READY line high. When the
processor returns the read signal to high level, the addressed
device will again tristate its bus drivers.
The BHE and A0 signals are used to select the proper byte or
bytes of memory or I/O word to be read or write.
The control of the bus is not regained by the processor until the
requesting master does not drop the HOLD pin low.
In this mode, the processor derives the status signal S2, S1, S0.
Another chip called bus controller derives the control signal using
this status information .
AEN and IOB are generally grounded. CEN pin is usually tied to
+5V. The significance of the MCE/PDEN output depends upon
the statusof the IOB pin.
In T2, 8288 will set DEN=1 thus enabling transceivers, and for an input
it will activate MRDC or IORC. These signals are activated until T4.
If reader input is not activated before T3, wait state will be inserted
between T3 and T4.
306
Dept. of ECE, ATMECE, MYSURU
PIO 8255 (cont..)
RD WR CS A1 A0 Function
X X 1 X X Data bus tristated
1 1 0 X X Data bus tristated
• D0-D7 : These are the data bus lines those carry data or
control word to/from the microprocessor.
• RESET : A logic high on this line clears the control word
register of 8255. All ports are set as input ports by default
after reset.
326
Dept. of ECE, ATMECE, MYSURU
Modes of Operation of 8255 (cont..)
338
Dept. of ECE, ATMECE, MYSURU
Modes of Operation of 8255 (cont..)
341
Dept. of ECE, ATMECE, MYSURU
342
Dept. of ECE, ATMECE, MYSURU
343
Dept. of ECE, ATMECE, MYSURU
Interfacing a Microprocessor To
Keyboard
• When you press a key on your computer, you are
activating a switch. There are many different ways of
making these switches. An overview of the
construction and operation of some of the most
common types.
1. Mechanical key switches: In mechanical-switch keys,
two pieces of metal are pushed together when you press
the key. The actual switch elements are often made of a
phosphor-bronze alloy with gold platting on the contact
areas. The key switch usually contains a spring to
return the key to the nonpressed position and perhaps a
small piece of foam to help damp out bouncing.
Dept. of ECE, ATMECE, MYSURU 344
Interfacing a Microprocessor To
Keyboard (cont..)
• Some mechanical key switches now consist of a molded
silicon dome with a small piece of conductive rubber
foam short two trace on the printed-circuit board to
produce the key pressed signal.
• Mechanical switches are relatively inexpensive but they
have several disadvantages. First, they suffer from
contact bounce. A pressed key may make and break
contact several times before it makes solid contact.
• Second, the contacts may become oxidized or dirty
with age so they no longer make a dependable
connection.
345
Dept. of ECE, ATMECE, MYSURU
Interfacing a Microprocessor To
Keyboard (cont..)
• Higher-quality mechanical switches typically have a
rated life time of about 1 million keystrokes. The
silicone dome type typically last 25 million
keystrokes.
2. Membrane key switches: These switches are really a
special type of mechanical switches. They consist of
a three-layer plastic or rubber sandwich.
• The top layer has a conductive line of silver ink
running under each key position. The bottom layer has
a conductive line of silver ink running under each
column of keys.
346
Dept. of ECE, ATMECE, MYSURU
Interfacing a Microprocessor To
Keyboard (cont..)
• When u press a key, you push the top ink line
through the hole to contact the bottom ink line.
• The advantages of membrane keyboards is that they
can be made as very thin, sealed units.
• They are often used on cash registers in fast food
restaurants. The lifetime of membrane keyboards
varies over a wide range.
3. Capacitive key switches: A capacitive keyswitch has
two small metal plates on the printed circuit board and
another metal plate on the bottom of a piece of foam.
348
Dept. of ECE, ATMECE, MYSURU
Interfacing a Microprocessor To
Keyboard (cont..)
4. Hall effect keyswitches: This is another type of switch
which has no mechanical contact. It takes advantage
of the deflection of a moving charge by a magnetic
field.
• A reference current is passed through a semiconductor
crystal between two opposing faces. When a key is
pressed, the crystal is moved through a magnetic field
which has its flux lines perpendicular to the direction
of current flow in the crystal.
• Moving the crystal through the magnetic field causes a
small voltage to be developed between two of the
other opposing faces of the crystal.
Dept. of ECE, ATMECE, MYSURU 349
Interfacing a Microprocessor To
Keyboard (cont..)
• This voltage is amplified and used to indicate that a key
has been pressed. Hall effect sensors are also used to
detect motion in many electrically controlled machines.
• Hall effect keyboards are more expensive because of the
more complex switch mechanism, but they are very
dependable and have typically rated lifetime of 100
million or more keystrokes.
350
Dept. of ECE, ATMECE, MYSURU
Dept. of ECE, ATMECE, MYSURU 351
Keyboard Circuit Connections and
Interfacing (cont..)
• In most keyboards, the keyswitches are connecting in
a matrix of rows and columns, as shown in fig.
• We will use simple mechanical switches for our
examples, but the principle is same for other type
of switches.
• Getting meaningful data from a keyboard, it requires
the following three major tasks:
1. Detect a keypress.
2. Debounce the keypress.
3. Encode the keypress
• The higher order lines of port A and port B are left unused.
The address of port A and port B will respectively 8000H
and 8002H while address of CWR will be 8006H. The
flow chart of the complete program is as given. The
control word for this problem will be 82H. Code segment
CS is used for storing the program code.
• Key Debounce : Whenever a mechanical push-button
is pressed or released once, the mechanical
components of the key do not change the position
smoothly, rather it generates a transient response .
I / P1 0 0 1
I / P2 0 1 0
I / P3 0 1 1
I / P4 1 0 0
I / P5 1 0 1
I / P6 1 1 0
I / P7 1 1 1
START
ALE
EOC
OE
O /P
CS + 5V
+ 5V Vcc Clock up
D0 – D7 PA7 – PA0 O7 – O0
Analog
PC7 EOC ADC I/P
A2
PC0 SOC
0808 Voltage
A1
OE GND
Reset 8255 +5V
ALE
A B C
IORD PB0
PB1
IOWR PB2
OUT 2 2 15 Vref in
GND 3 14 V+
MSB B1 4 13 NC
AD 7523
B2 5 12 NC
B3 6 11 B8 LSB
B4 7 10 B7
B5 8 9 B6
R1 R3 R5 R7
2R 2R 2R 2R 2R
2R
-
V0
R2 R4 R6 R8 +
15 14
16
RFB
PA7 MSB 4
OUT1 1 -
8255A VZ V0
LSB 2 +
PA 0 11 OUT2
AD7523
CS
GND
3
396
Dept. of ECE, ATMECE, MYSURU
8254 Programming
NULL
OUTPUT COUNT RW1 RW0 M2 M1 M0 BCD
NULL COUNT: goes low when the new count written to a counter is
actually loaded into the counter
Byte addressable and byte-swapping signals
signals
To 8088 from 8088
Word: 5A2F
CLK
18001 5A High byte of word
GND
18000 2F Low byte of word
8088 signal classification
Memory locations
403
Dept. of ECE, ATMECE,
MYSURU
Organization of 8088
Address bus (20 bits)
AH AL General purpose
BH BL register
CH CL
Execution Unit DH DL
(EU) Data bus
SP CS (16 bits)
Segment
BP register DS
SI SS
DI ALU Data bus ES
(16 bits)
IP
Bus
control
ALU Instruction Queue External bus
EU
control
Flag register
Bus Interface Unit (BIU)
404
Dept. of ECE, ATMECE, MYSURU
General Purpose Registers
15 8 7 0
AX AH AL Accumulator
BX BH BL Base
Data Group
CX CH CL Counter
DX DH DL Data
SP Stack Pointer
BP Base Pointer
Pointer and
Index Group
SI Source Index
DI Destination Index
405
Dept. of ECE, ATMECE, MYSURU
Arithmetic Logic Unit (ALU)
A B F Y
n bits n bits
0 0 0 A+B
Carry 0 0 1 A -B
0 1 0 A -1
Y= 0 ? F 0 1 1 A and B
1 0 0 A or B
A>B?
1 0 1 not A
Y
Signal F control which function will be conducted by ALU.
Signal F is generated according to the current instruction.
407
Dept. of ECE, ATMECE, MYSURU
Instruction Machine Codes
Instruction machine codes are binary numbers
For Example:
410
Dept. of ECE, ATMECE, MYSURU
Memory Segmentation
A segment is a 64KB block of memory starting from any 16-byte
boundary
For example: 00000, 00010, 00020, 20000, 8CE90, and E0840 are all valid
segment addresses
The requirement of starting from 16-byte boundary is due to the 4-bit
left shifting
DS Data Segment
SS Stack Segment
ES Extra Segment
411
Dept. of ECE, ATMECE, MYSURU
Memory Address Calculation
Examples
CS 3 4 8 A 0 SS 5 0 0 0 0
IP + 4 2 1 4 SP + F F E 0
Instruction address 3 8 A B 4 Stack address 5 F F E 0
DS 1 2 3 4 0
DI + 0 0 2 2
Data address 1 2 3 6 2
412
Dept. of ECE, ATMECE, MYSURU
Fetching Instructions
Where to fetch the next instruction?
8088 Memory
CS 1 2 3 4
IP 0012 12352 MOV AL, 0
12352
Update IP
— After an instruction is fetched, Register IP is updated as follows:
— For Example: the length of MOV AL, 0 is 2 bytes. After fetching this instruction,
the IP is updated to 0014
DS 1 2 3 4 0 (assume DS=1234H)
0 3 0 0
Memory address 1 2 6 4 0
DS 1 2 3 4 0 (assume DS=1234H)
0 3 1 0 (assume SI=0310H)
Memory address 1 2 6 5 0
Control Unit
Execution Unit
Vcc TAG
CLK 79 0 TAG
0 register
INT 8-register stack, each has 80 bits to
BHE/S7 TAG 7
Bus
tracking Floating point arithmetic module
AD15 - AD0 control
logic, Status Register 16 bit
A19/S6 A16/S3 instruction
queue Control Register
QS1-QS0
16 LBS of instruction address
RQ/GT0 4MSB inst address 0 11 LSB of op code
16 LSB of operand address
RQ/GT1
Busy 4 MSB of operand address 0
Ready vss
Reset Dept. of ECE, ATMECE, MYSURU 422
Block Diagram of 8087
Control Unit Numeric execution unit
Control word Exponent bus Fraction bus
Programm
Status word
able shifter
Exponent
Module interface
16
Data
Micro control 68 Arithmetic
buffer unit module
Data
16 64
Operand temporary
queue 16 register
7
Status Tag
Addressing 8 Register Stack
word
bus tracking
Exception 80 Bits
Address pointer 0
Dept. of ECE, ATMECE, MYSURU 423
Control Unit
B C3 ST C2 C1 C0 ES PE UE OE ZE DE IE
IC RC PC PM UM OM ZM DM IM
• IC Infinity control
• RC Rounding control
• PC Precision control
• PM Precision control
• UM Underflow mask
• OM Overflow mask
• ZM Division by zero mask
• DM Denormalized operand
• IM mask Invalid operand mask
Dept. of ECE, ATMECE, MYSURU 430
Control Register (cont..)
IC –Infinity control selects INFINITY CONTROL
either affine or projective
infinity. Affine allows 0 = Projective
positive and negative 1 = Affine
infinity, while projective
assumes infinity
is unsigned. ROUNDING CONTROL
RC –Rounding control 00=Round to nearest or even
determines the type of 01=Round down towards minus infinity
rounding. 10=Round up towards plus infinity
11=Chop or truncate towards zero
RQ/GT1 of 8086.
BUSY signal 8087 is connected to TEST pin of 8086.
Interrupt output INT of the 8087 to NMI input of 8086.
This intimates an error condition.
Dept. of ECE, ATMECE, 43
MYSURU 5
Circuit Connection for 8086 –
8087 (cont.)
The main purpose of the circuitry between the INT output
of 8087 and the NMI input is to make sure that an NMI
signal is not present upon reset, to make it possible to
mask NMI input and to make it possible for other
devices to
cause an NMI interrupt.
BHE pin is connected to the system BHE line to enable
the upper bank of memory.
The RQ/GT1 input is available so that another
coprocessor such as 8089 I/O processor can be connected
and function in parallel with the 8087.
(a)
(b)
RQ/GT1 of 8086.
BUSY signal 8087 is connected to TEST pin of 8086.
Interrupt output INT of the 8087 to NMI input of 8086.
This intimates an error condition.
A WAIT instruction is passed to keep looking at its TEST pin,
until it finds pin Low to indicates that the 8087 has completed
the computation.
Dept. of ECE, ATMECE, 44
MYSURU 8
Von Neumann and Harvard architecture
449
Dept. of ECE, ATMECE, MYSURU
Interfacing
SYNCHRONIZATION must be established between the
processor and coprocessor in two situations.
a) The execution of an ESC instruction that require the
participation of the NUE must not be initiated if the NUE
has not completed the execution of the previous instruction.
b) When a processor instruction accesses a memory
location that is an operand of a previous coprocessor
instruction .In this case CPU must synchronize with NPX
to ensure that it has completed its instruction.
Processor WAIT instruction is provided.