MALP Digitization
MALP Digitization
by
MICROPROCESSOR8085
BasicConceptsof Microprocessors
Differencesbetween:
Microcomputer – a computer with a microprocessor as its CPU. Includes
memory, IMicroprocessor – silicon chip which includes
ALU, register circuits & control circuits/O etc.
Microcontroller – silicon chip which includes microprocessor, memory & I/O in a
single package.
What is a Microprocessor?
The word comes from the combination micro and processor.
Processor means a device that processes whatever. In this context processor
means a device that processes numbers, specifically binary numbers, 0’s and 1’s.
To process means to manipulate. It is a general term that describes all
manipulation. Again in this content, it means to perform certain operations on
the numbers that depend on the microprocessor’s design.
What is a microprocessor?
The microprocessor is a programmable device that takes in numbers, performs on
them arithmetic or logical operations according to the program stored in memory and then
produces other numbers as a result.
Lets expand each of the underlined words:
Programmable device: The microprocessor can perform different sets
of operations on the data it receives depending on the sequence of
instructions supplied in the given program.
Microprocessor and Microcontroller with 8085 and 8086
2
Stored in memory :
First, what is memory?
Memory is the location where information is kept while not in current use.
Memory is a collection of storage devices. Usually, each storage device holds
one bit. Also, in most kinds of memory, these storage devices are grouped
into groups of 8. These 8 storage locations can only be accessed together. So,
one can only read or write in terms of bytes to and from memory.
Memory is usually measured by the number of bytes it can hold.It is
measured in Kilos, Megas and lately Gigas. A Kilo in computer language is 210
=1024. So, a KB (KiloByte) is 1024 bytes. Mega is 1024 Kilos and Giga is 1024
Mega.
When a program is entered into a computer, it is stored in memory. Then as
the microprocessor starts to execute the instructions, it brings the
instructions from memory one at a time.
Memory is also used to hold the data.
The microprocessor reads (brings in) the data from memory when it needs it
and writes (stores) the results into memory when it is done.
Produces:
For the user to see the result of the execution of the program, the results
must be presented in a human readable form.
The results must be presented on an output device.This can be the monitor, a
paper from the printer, asimple LED or many other forms.
Input Output
Memory
Microprocessor and Microcontroller with 8085 and 8086
4
Memory
Memory stores information such as instructions and data in binary format (0 and 1).
It provides this information to the microprocessor whenever it is needed.
Usually, there is a memory “sub-system” in a microprocessor-based system. This
sub-system includes:
The registers inside the microprocessor
Read Only Memory (ROM)
Used to store information that does not change.
Random Access Memory (RAM) (also known asRead/Write Memory).
(Used to store information supplied by the user. Such as programs
and data.)
To execute a program:
The user enters its instructions in binary format into the memory.
Microprocessor and Microcontroller with 8085 and 8086
5
Machine Language
The number of bits that form the “word” of a microprocessor is fixed for that
particular processor.
These bits define a maximum number of combinations.
• For example an 8-bit microprocessor can have at most 28 = 256
different combinations
However, in most microprocessors, not all of these combinations are used.
Microprocessor and Microcontroller with 8085 and 8086
6
Assembly Language
Entering the instructions using hexadecimal is quite easier than entering the binary
combinations.
However, it still is difficult to understand what a program written in
hexadecimal does.
So, each company defines a symbolic code for the instructions.
These codes are called “mnemonics”.
The mnemonic for each instruction is usually a group of letters that
suggest the operation performed.
Using the same example from before,
00111100 translates to 3C in hexadecimal (OPCODE)
Its mnemonic is: “INR A”.
INR stands for “increment register” and A is short for accumulator.
Another example is: 1000 0000,
Which translates to 80 in hexadecimal?
Its mnemonic is “ADD B”.
“Add register B to the accumulator and keep the result in the
accumulator”.
It is important to remember that a machine language and its associated assembly
language are completely machining dependent. In other words, they are not
transferable from one microprocessor to a different one.
For example, Motorola has an 8-bit microprocessor called the 6800.
– The 8085 machine language is very different from that of the 6800. So is the
assembly language.
Microprocessor and Microcontroller with 8085 and 8086
7
– A program written for the 8085 cannot be executed on the 6800 and vice
versa.
The ALU
In addition to the arithmetic & logic circuits, the ALU includes the accumulator,
which is part of every arithmetic & logic operation.
Also, the ALU includes a temporary register used
for holding data temporarily during the execution of the operation. This temporary
register is not accessible by the programmer.
Microprocessor and Microcontroller with 8085 and 8086
11
Registers
General Purpose Registers
B, C, D, E, H & L (8 bit registers)
Can be used singly
Or can be used as 16 bit register pairs. i.e; BC, DE, HL
H & L can be used as a data pointer (holds memory address)
Special Purpose Registers
Accumulator (8 bit register)
Store 8 bit data
Store the result of an operation
Store 8 bit data during I/O transfer
Flag Register
8 bit register – shows the status of the microprocessor before/after an operation.
S (sign flag), Z (zero flag), AC (auxillary carry flag), P (parity flag) & CY (carry flag).
Sign Flag
Used for indicating the sign of the data in the accumulator.
The sign flag is set if negative (1 – negative).
The sign flag is reset if positive (0 –positive).
Zero Flag
Is set if result obtained after an operation is 0.
Is set following an increment or decrement operation of that register.
10110011
+ 01001101
1 00000000
Microprocessor and Microcontroller with 8085 and 8086
12
Carry Flag
Is set if there is a carry or borrow from arithmetic operation.
1011 0101 1011 0101
+ 0110 1100 - 1100 1100
Carry 1 0010 0001 Borrow 1 1110 1001
Parity Flag
Is set if parity is even.
Is cleared if parity is odd.
Demultiplexing AD7-AD0
From the above description, it becomes obvious that the AD7– AD0 lines are serving
a dual purpose and that they need to be demultiplexed to get all the information.
The high order bits of the address remain on the bus for three clock periods.
However, the low order bits remain for only one clock period and they would be lost
if they are not saved externally. Also, notice that the low order bits of the address
disappear when they are needed most.
To make sure we have the entire address for the full three clock cycles, we will use
an external latch to save the value of AD7– AD0 when it is carrying the address bits.
We use the ALE signal to enable this latch.
Given that ALE operates as a pulse during T1, we willbe able to latch the address.
Then when ALE goes low, the address is saved and the AD7– AD0 lines can be used
for their purpose as the bi-directional data lines.
Microprocessor and Microcontroller with 8085 and 8086
14
Introduction
To
8085 Instructions
Microprocessor and Microcontroller with 8085 and 8086
17
Arithmetic Operations
o Addition (ADD, ADI):
Any 8-bit number.
The contents of a register.
The contents of a memory location.
• Can be added to the contents of the accumulator and the result is stored in the
accumulator.
o Subtraction (SUB, SUI):
Any 8-bit number
The contents of a register
The contents of a memory location
• Can be subtracted from the contents of the accumulator. The result is stored in the
accumulator.
Arithmetic Operations
Increment (INR) and Decrement (DCR):
• The 8-bit contents of any memory location or any register can be directly
incremented or decremented by 1.
• No need to disturb the contents of the accumulator.
Manipulating Addresses
Now that we have a 16-bit address in a register pair, how do we manipulate it?
– It is possible to manipulate a 16-bit address stored in a register pair as one entity
using some special instructions.
• INX Rp (Increment the 16-bit number in the register pair)
• DCX Rp (Decrement the 16-bit number in the register pair)
– The register pair is incremented or decremented as one entity. No need to worry
about a carry from the lower
8-bits to the upper. It is taken care of automatically.
Logic Operations
These instructions perform logic operations on the contents of the accumulator.
– ANA, ANI, ORA, ORI, XRA and XRI
– An 8-bit number
– The contents of a register
– The contents of a memory location
• Destination: Accumulator
ANA R/M AND Accumulator WithReg/Mem
ANI # AND Accumulator With an 8-bit number
ORA R/M OR Accumulator WithReg/Mem
ORI # OR Accumulator With an 8-bit number
XRA R/M XOR Accumulator WithReg/Mem
XRI # XOR Accumulator With an 8-bit number
Microprocessor and Microcontroller with 8085 and 8086
21
Logic Operations
- Complement:
• 1’s complement of the contents of the accumulator.
CMA No operand
Logical Operations
Compare
• Compare the contents of a register or memory location with the contents of the
accumulator.
– CMP R/M Compare the contents of the register or memory location to the
contents of the accumulator.
– CPI # Compare the 8-bit number to the contents of the accumulator.
• The compare instruction sets the flags (Z, Cy, and S).
• The compare is done using an internal subtraction that does not change the contents
of the accumulator.
A – (R / M / #)
Branch Operations
Two types:
1. Unconditional branch.
Go to a new location no matter what.
2. Conditional branch.
Go to a new location if the condition is true.
1.Unconditional branch
– JMP Address
Jump to the address specified (Go to).
– CALL Address
Jump to the address specified but treat it as a subroutine.
– RET
Return from a subroutine.
o The addresses supplied to all branch operations must be16-bits.
2.Conditional branch
Go to new location if a specified condition is met.
– JZ Address (Jump on Zero)
Go to address specified if the Zero flag is set.
Microprocessor and Microcontroller with 8085 and 8086
23
Machine Control
HLT
• Stop executing the program.
NOP
• No operation
• Exactly as it says, do nothing.
• Usually used for delay or to replace instructions during debugging.
Operand Types
There are different ways for specifying the operand:
– There may not be an operand (implied operand)
o CMA
– The operand may be an 8-bit number (immediate data)
o ADI 4FH
– The operand may be an internal register (register)
o SUB B
– The operand may be a 16-bit address (memory address)
o LDA 4000H
Microprocessor and Microcontroller with 8085 and 8086
24
Instruction Size
Depending on the operand type, the instruction may have different sizes. It will
occupy a different number of memory bytes.
– Typically, all instructions occupy one byte only.
– The exception is any instruction that contains immediate data or a memory address.
o Instructions that include immediate data use two bytes.
– One for the opcode and the other for the 8-bit data.
o Instructions that include a memory address occupy three bytes.
– One for the opcode, and the other two for the 16-bit address.
Addressing Modes
The microprocessor has different ways of specifying the data for the instruction.
These are called “addressing modes”.
• The 8085 has four addressing modes:
o Implied CMA
o Immediate MVI B, 45
o Direct LDA 4000
o Indirect LDAX B
• Load the accumulator with the contents of the memory location whose address is
stored in the register pair BC).
Data Formats
– In an 8-bit microprocessor, data can be represented in one of four formats:
o ASCII
o BCD
o Signed Integer
o Unsigned Integer.
– It is important to recognize that the microprocessor deals with 0’s and 1’s.
o It deals with values as strings of bits.
o It is the job of the user to add a meaning to these strings.
Data Formats
Assume the accumulator contains the following value: 0100 0001.
– There are four ways of reading this value:
• It is an unsigned integer expressed in binary, the equivalent decimal number would
be 65.
• It is a number expressed in BCD (Binary Coded Decimal) format. That would make it, 41.
• It is an ASCII representation of a letter. That would make it the letter A.
• It is a string of 0’s and 1’s where the 0th and the 6th bits are set to 1 while all other bits
are set to 0.
Microprocessor and Microcontroller with 8085 and 8086
26
Count
ers &
Time
Microprocessor and Microcontroller with 8085 and 8086
27
Counters
• A loop counter is set up by loading a register with a certain value
• Then using the DCR (to decrement) and INR (to increment) the contents of the
register are updated.
• A loop is set up with a conditional jump instruction that loops back or not depending
on whether the count has reached the termination count.
• The operation of a loop counter can be described using the following flowchart.
LXI B, 1000H
LOOP DCX B
MOV A, C ORA B
JNZ LOOP
Delays
• It was shown in Chapter 2 that each instruction passes through different
combinations of Fetch, Memory Read, and Memory Write cycles.
• Knowing the combinations of cycles, one can calculate how long such an instruction
would require to complete.
• The table in Appendix F of the book contains a column with the title B/M/T.
o B for Number of Bytes
o M for Number of Machine Cycles
o T for Number of T-State.
• Knowing how many T-States an instruction requires, and keeping in mind that a T-
State is one clock cycle long, we can calculate the time using the following formula:
Delay = No. of T-States / Frequency
• For example a “MVI” instruction uses 7 T-States. Therefore, if the Microprocessor is
running at 2MHz, the instruction would require 3.5 µSeconds to complete.
Delay loops
• We can use a loop to produce a certain amount of time delay in a program.
• The following is an example of a delay loop:
MVI C, FFH 7 T-States
LOOP DCR C 4 T-States
JNZ LOOP 10 T-States
• The first instruction initializes the loop counter and is executed only once requiring
only 7 T-States.
• The following two instructions form a loop that requires 14 T-States to execute and
is repeated 255 times until C becomes 0.
• We need to keep in mind though that in the last iteration of the loop, the JNZ
instruction will fail and require only 7 T-States rather than the 10.
• Therefore, we must deduct 3 T-States from the total delay to get an accurate delay
calculation.
• To calculate the delay, we use the following formula:
Tdelay = TO + TL
Microprocessor and Microcontroller with 8085 and 8086
29
Nested Loops
Nested loops can be easily setup in Assembly language by using two registers for the
two loop counter and updating the right register in the right loop.
In the figure, the body of loop2 can be before or after loop1.
Timing Diagram
Representation of Various Control signals generated during Execution of an
Instruction.
Following Buses and Control Signals must be shown in a
Timing Diagram:
• Higher Order Address Bus.
• Lower Address/Data bus
• ALE
• RD
• WR
• IO/M
Timing Diagram(Cont.)
Instruction:
A000h MOV A,B
Corresponding Coding:
A000h 78
Instruction:
A000H MOV A,B
Corresponding Coding
A000H 78
Microprocessor and Microcontroller with 8085 and 8086
33
Timing Diagram(Cont.)
Instruction:
A000h MVI A,45h
Corresponding Coding:
A000h 3E
A001h 45
Instruction:
A000h MVI A,45h
Corresponding Coding:
A000h 3E
A001h 45
Microprocessor and Microcontroller with 8085 and 8086
34
Instruction:
A000h LXI A,FO45h
Corresponding Coding:
A000h 21
A001h 45
A002h F0
Instruction:
A000h LXI A,FO45h
Corresponding Coding:
A000h 21
A002h F0
Microprocessor and Microcontroller with 8085 and 8086
35
Timing Diagram
Instruction:
A000h MOV A,M
Corresponding Coding:
A000h 7E
Microprocessor and Microcontroller with 8085 and 8086
36
Timing Diagram
Instruction:
A000h MOV M,A
Corresponding Coding:
A000h 77
Microprocessor and Microcontroller with 8085 and 8086
37
Timing Diagram
Microprocessor and Microcontroller with 8085 and 8086
38
Chapter 9
Stack and Subroutines
Microprocessor and Microcontroller with 8085 and 8086
39
The Stack
The stack is an area of memory identified by the programmer for temporary storage of
information.
• The stack is a LIFO(Last In First Out) structure.
• 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.
Given that the stack grows backwards into memory, it is customary to place the
bottom of the stack at the end of memory to keep it as far away from user programs as
possible.
• In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
LXI SP, FFFFH
• This sets the Stack Pointer to location FFFFH (end of memory for the 8085).
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
...
POP D
POP B
Subroutines
• A subroutine is a group of instructions that will be used repeatedly in different
locations of the program.
Rather than repeat the same instructions several times, they can be grouped
into a subroutine that is called from the different locations.
• In Assembly language, a subroutine can exist anywhere in the code.
However, it is customary to place subroutines separately from the
main program.
• The 8085 has two instructions for dealing with subroutines.
The CALL instruction is used to redirect program execution to the subroutine.
The RTE insutruction is used to return the execution to the calling routine.
Cautions:
• The CALL instruction places the return address at the two memory locations
immediately before where the Stack Pointer is pointing.
o You must set the SP correctly BEFORE using theCALL instruction.
• The RTE instruction takes the contents of the two memory locations at the top of the
stack and uses these as the return address.
o Do not modify the stack pointer in a subroutine. You will loose the return
address.
A Proper Subroutine:
• According to Software Engineering practices, a proper subroutine:
o Is only entered with a CALL and exited with an RTE
o Has a single entry point
Do not use a CALL statement to jump into different points of the same
subroutine.
o Has a single exit point
There should be one return statement from any subroutine.
• Following these rules, there should not be any confusion with PUSH and POP usage.
Microprocessor and Microcontroller with 8085 and 8086
43
Tri-State Buffers
An important circuit element that is used extensively in memory.
This buffer is a logic circuit that has three states:
Logic 0, logic1, and high impedance.
When this circuit is in high impedance mode it looks as if it is disconnected from the
output completely.
A Memory “Register”
If we take four of these latches and connect them together, we would have a 4-bit
memory register.
Microprocessor and Microcontroller with 8085 and 8086
45
Since we have tri-state buffers on both the inputs and outputs of the flip flops, we
can actually use.
Microprocessor and Microcontroller with 8085 and 8086
48
Dimensions of Memory
Memory is usually measured by two numbers: its length and its width (Length X Width).
The length is the total number of locations.
The width is the number of bits in each location.
The length (total number of locations) is a function of the number of address lines.
# of memory locations = 2( # of address lines)
So, a memory chip with 10 address lines would have
210 = 1024 locations (1K)
Looking at it from the other side, a memory chip with 4K locations would need
Log2 4096=12 address lines
Chip Select
Usually, each memory chip has a CS (Chip Select) input. The chip will only work if an
active signal is applied on that input.
To allow the use of multiple chips in the make up of memory, we need to use a
number of the address lines for the purpose of “chip selection”.
These address lines are decoded to generate the 2n necessary CS inputs for the
memory chips to be used.
Microprocessor and Microcontroller with 8085 and 8086
49
Depending on the combination on the address lines A15 - A10 , the address range of
the specified chip is determined.
Chip Select Example :
A chip that uses the combination A15 - A10 =001000 would have addresses that
range from2000H to 23FFH.
Microprocessor and Microcontroller with 8085 and 8086
51
Keep in mind that the 10 address lines on the chip gives a range of 00 0000 0000 to
11 1111 1111 or 000H to 3FFH for each of the chips.
The memory chip in this example would require the following circuit on its chip
select input:
Now the chip would have addresses ranging from: 2400 to 27FF.
Changing the combination of the address bits connected to the chip select changes
the address range for the memory chip.
Chip Select Example :
To illustrate this with a picture:
In the first case, the memory chip occupies the piece of the memory map identified
as before.
In the second case, it occupies the piece identified as after.
Microprocessor and Microcontroller with 8085 and 8086
52
Data Lines
All of the above discussion has been regarding memory length. Lets look at memory
width.
We said that the width is the number of bits in each memory word.
We have been assuming so far that our memory chips have the right width.What if
they don’t?
It is very common to find memory chips that have only 4 bits per location. How
would you design a byte wide memory system using these chips?
We use two chips for the same address range. One chip will supply 4 of the data
bits per address and the other chip supply the other 4 data bits for the same address.
Microprocessor and Microcontroller with 8085 and 8086
53
Interrupts
Interrupt is a process where an external device can get the attention of the
microprocessor.
o The process starts from the I/O device
o The process is asynchronous.
Interrupts can be classified into two types:
o Maskable (can be delayed)
o Non-Maskable (can not be delayed)
• Interrupts can also be classified into:
o Vectored (the address of the service routine is hard-wired)
o Non-vectored (the address of the service routine needs to be supplied
externally)
An interrupt is considered to be an emergency signal.
o The Microprocessor should respond to it as soon as possible.
When the Microprocessor receives an interrupt signal, it suspends the currently
executing program and jumps to an Interrupt Service Routine (ISR) to respond to the
incoming interrupt.
o Each interrupt will most probably have its own ISR.
Responding to Interrupts
Responding to an interrupt may be immediate or delayed depending on whether the
interrupt is maskable or non-maskable and whether interrupts are being masked or not.
There are two ways of redirecting the execution to the ISR depending on whether
the interrupt is vectored or non-vectored.
o The vector is already known to the Microprocessor.
o The device will have to supply the vector to theMicroprocessor.
The 8085 recognizes 8 RESTART instructions: RST0 - RST7.Each of these would send the
execution to a predetermined hard-wired memory location:
Restart Sequence
The restart sequence is made up of three machine cycles
In the 1st machine cycle:
• The microprocessor sends the INTA signal.
• While INTA is active the microprocessor reads the data lines expecting to receive,
from the interrupting device, the opcode for the specific RST instruction.
In the 2nd and 3rd machine cycles: the 16-bit address of the next instruction
is saved on the stack.Then the microprocessor jumps to the address associated with
the specified RST instruction.
• The location in the IVT associated with the RST instruction can not hold the complete
service routine.
o The routine is written somewhere else in memory.
o Only a JUMP instruction to the ISR’s location is kept in the IVT block.
Microprocessor and Microcontroller with 8085 and 8086
56
During the interrupt acknowledge machine cycle, (the 1st machine cycle of the RST
operation):
o The Microprocessor activates the INTA signal.
o This signal will enable the Tri-state buffers, which will place the value EFH on
the data bus.
o Therefore, sending the Microprocessor the RST 5 instruction.
The RST 5 instruction is exactly equivalent to CALL 0028H.
Microprocessor and Microcontroller with 8085 and 8086
57
The vectors for these interrupt fall in between the vectors for the RST instructions.
That’s why they have names like RST 5.5 (RST 5 and a half).
Maskable Interrupts
Microprocessor and Microcontroller with 8085 and 8086
60
Triggering Levels
• RST 7.5 is positive edge sensitive.
o When a positive edge appears on the RST7.5 line, a logic 1 is stored in the
flip-flop as a “pending” interrupt.
o Since the value has been stored in the flip flop, the line does not have to be
high when the microprocessor checks for the interrupt to be recognized.
o The line must go to zero and back to one before a new interrupt is
recognized.
• RST 6.5 and RST 5.5 are level sensitive.
o The interrupting signal must remain present until the microprocessor checks
for interrupts.
• Bits 0-2 show the current setting of the mask for each of RST 7.5, RST 6.5 and RST 5.5
o They return the contents of the three mask flip flops.
o They can be used by a program to read the mask settings in order to modify
only the right mask.
• Bit 3 shows whether the maskable interrupt process is enabled or not.
o It returns the contents of the Interrupt Enable Flip Flop.
o It can be used by a program to determine whether or not interrupts are
enabled.
• Bits 4-6 show whether or not there are pending interrupts on RST 7.5, RST 6.5, and
RST 5.5
o Bits 4 and 5 return the current value of the RST5.5 and RST6.5 pins.
o Bit 6 returns the current value of the RST7.5 memory flip flop.
• Bit 7 is used for Serial Data Input.
o The RIM instruction reads the value of the SID pin on the microprocessor and
returns it in this bit.
Pending Interrupts
Since the 8085 has five interrupt lines, interrupts may occur during an ISR and
remain pending.
– Using the RIM instruction, the programmer can read the status of the interrupt lines
and find if there are any pending interrupts.
– The advantage is being able to find about interrupts onRST 7.5, RST 6.5, and RST 5.5
without having to enable low level interrupts like INTR.
– Given that both RIM and SIM use the Accumulator, we can use some logical
operations to masks the un-needed values returned by RIM and turn them into the
values needed by SIM.
Assume the RST5.5 and RST7.5 are enabled and the interrupt process is disabled.
TRAP
• TRAP is the only non-maskable interrupt.
o It does not need to be enabled because it cannot be disabled.
• It has the highest priority amongst interrupts.
• It is edge and level sensitive.
o It needs to be high and stay high to be recognized.
o Once it is recognized, it won’t be recognized again until it goes low, then high
again.
• TRAP is usually used for power failure and emergency shutoff.
5. The 8259A responds by placing the op-code for theCALL instruction (CDH) on the
data bus.
6. When the microprocessor receives the op-code for CALL instead of RST, it recognizes
that the device will be sending 16 more bits for the address.
7. The microprocessor sends a second INTA signal.
8. The 8259A sends the high order byte of the ISR’s address.
9. The microprocessor sends a third INTA signal.
10. The 8259A sends the low order byte of the ISR’s address.
11. The microprocessor executes the CALL instruction and jumps to the ISR.
Rate of Transmission
For parallel transmission, all of the bits are sent at once.
• For serial transmission, the bits are sent one at a time.
o Therefore, there needs to be agreement on how “long” each bit stays on the
line.
• The rate of transmission is usually measured inbits/second or baud.
Transmitting a Character
To send the character A over a serial communication line at a baud rate of 56.6 K:
– ASCII for A is 41H = 01000001.
– Must add a start bit and two stop bits:
o 11 01000001 0
– Each bit should last 1/56.6K = 17.66 µ Sec.
o Known as bit time.
Microprocessor and Microcontroller with 8085 and 8086
70
– Set up a delay loop for 17.66 µ Sec and set the transmission line to the different bits
for the duration of the loop.
Error Checking
Various types of errors may occur during transmission.
– To allow checking for these errors, additional information is transmitted with the
data.
Error checking techniques:
– Parity Checking.
– Checksum.
These techniques are for error checking not correction.
– They only indicate that an error has occurred.
– They do not indicate where or what the correct information is.
Parity Checking
Make the number of 1’s in the data Odd or Even.
– Given that ASCII is a 7-bit code, bit D7 is used to carry the parity information.
Even Parity
– The transmitter counts the number of ones in the data. If there is an odd number of
1’s, bit D7 is set to 1 to make the total number of 1’s even.
– The receiver calculates the parity of the received message, it should match bit D7.
If it doesn’t match, there was an error in the transmission.
Check Sum
Used when larger blocks of data are being transmitted.
• The transmitter adds all of the bytes in the message without carries. It then
calculates the 2’s complement of the result and send that as the last byte.
• The receiver adds all of the bytes in the message including the last byte. The result
should be 0.
o If it isn’t an error has occurred.
RS 232
A communication standard for connecting computers to printers, modems, etc.
– The most common communication standard.
– Defined in the 1950’s.
– It uses voltages between +15 and –15 V.
– Restricted to speeds less than 20 K baud.
– Restricted to distances of less than 50 feet (15 m).
The original standard uses 25 wires to connect the two devices.
Microprocessor and Microcontroller with 8085 and 8086
71
Serial Transmission
Microprocessor and Microcontroller with 8085 and 8086
72
Serial Reception
Ports
Using the SOD and SID pins, the user would not need to bother with setting up input
and output ports.
– The two pins themselves can be considered as the ports.
– The instructions SIM and RIM are similar to the OUT and IN instructions except that
they only deal with the 1-bit SOD and SID ports.
Example
Transmit an ASCII character stored in register B using the SOD line.
SODDATA MVI C, 0BH ; Set up counter for 11 bits
XRA A ; Clear the Carry flag
NXTBITMVI A, 80H ; Set D7 =1
RAR ; Bring Carry into D7 and set D6 to 1
SIM ; Output D7 (Start bit)
CALL BITTIME
STC ; Set Carry to 1
MOV A, B ; Place character in A
RAR ; Shift D0 of the character to the carry
Shift 1 into bit D7
MOV B, A ; Save the interim result
DCR C ; decrement bit counter
JNZ NXTBIT
Microprocessor and Microcontroller with 8085 and 8086
76
Microprocessor and Microcontroller with 8085 and 8086
77
PROBLEM 1)
Interface 8255a to a 8085 microprocessor using I/O-mapped - I/O technique so that
Port a have address 80H in the system.
Determine addresses of Ports B,C and control register.
Write an ALP to configure port A and port CL as output ports and port B and port CU
as input ports in mode 0.
Connect DIP switches connected to the to input ports andLEDs to the output ports .
Read switch positions connected to port A and turn on the respective LEDs of port b.
Read switch positions of port CL and display the reading at port CU.
Problem 2)
Microprocessor and Microcontroller with 8085 and 8086
80
Write an ALP to set bits PC7 and PC 3 and reset them after 10 ms in BSR mode.
Problem 3)
Initialize 8255A in mode 1 to configure Port A as an input port and Port B as an
output port.
Assuming that an A-to-d converter is connected with port A as an interrupt I/O and a
printer is connected with port B as a status check I/O
Microprocessor and Microcontroller with 8085 and 8086
84
8086MICROPROCESSOR
Microprocessor and Microcontroller with 8085 and 8086
85
Pinouts
Microprocessor and Microcontroller with 8085 and 8086
86
8086Pins
The 8086 comes in a 40 pin package which means that some pins have more than
one use or are multiplexed. The packaging technology of time limited the number of pin
that could be used.
In particular, the address lines 0 - 15 are multiplexed with data lines 0-15, address
lines 16-19 are multiplexed with status lines. These pins are
AD0 - AD15, A16/S3 - A19/S6
The 8086 has one other pin that is multiplexed and this is BHE’/S7.BHE stands for
Byte High Enable. This is an active low signal that is asserted when there is data on the
upper half of the data bus.
The 8086 has two modes of operation that changes the function of some pins. The
SDK-86 uses the 8086 in the minimum mode with the MN/MX’ pin tied to5 volts. This is a
simple single processor mode. The IBM PC uses an 8088 in the maximum mode with the
MN/MX” pin tied to ground. This is the mode required for a coprocessor like the 8087.
NMI (Non Maskable Interrupt): transition from low to high causes aninterrupt. Used for
emergencies such as power failure.
INTR (Interrupt request): masked by the IF bit in FLAG register.
CLK (Clock): 33% duty cycle, i.e., high 1/3 the time.
8086 Features
16-bit Arithmetic Logic Unit
• 16-bit data bus (8088 has 8-bit data bus)
• 20-bit address bus - 220 = 1,048,576 = 1 meg
The address refers to a byte in memory. In the 8088, these bytes come in on the 8-bit
data bus. In the 8086, bytes at even addresses come in on the lowhalf of the data bus (bits
0-7) and bytes at odd addresses come in on the upper half of the data bus (bits 8-15).
The 8086 can read a 16-bit word at an even address in one operation and at an odd
address in two operations. The 8088 needs two operations in either case.
The least significant byte of a word on an 8086 family microprocessor is at the lower
address.
Microprocessor and Microcontroller with 8085 and 8086
88
8086 Architecture
• The 8086 has two parts, the Bus Interface Unit (BIU) and the Execution Unit (EU).
• The BIU fetches instructions, reads and writes data, and computes the20-bit address.
• The EU decodes and executes the instructions using the 16-bit ALU.
• The BIU contains the following registers: IP - the Instruction Pointer
CS - the Code Segment Register,DS - the Data Segment Register,SS - the Stack Segment
Register,ES - the Extra Segment Register
The BIU fetches instructions using the CS and IP, written CS:IP, to construct the 20-bit
address. Data is fetched using a segment register (usually the DS) and an effective address
(EA) computed by the EU depending on the addressing mode.
AX - the Accumulator
BX - the Base Register
CX - the Count Register
DX - the Data Register
SP - the Stack Pointer / defaults to stack segment
BP - the Base Pointer /
SI - the Source Index Register
DI - the Destination Register
These are referred to as general-purpose registers, although, as seen by their names,
they often have a special-purpose use for some instructions.
The AX, BX, CX, and DX registers can be considers as two 8-bit registers, a High byte
and a Low byte. This allows byte operations and compatibility with the previous generation
of 8-bit processors, the 8080 and 8085. 8085 source code could be translated in 8086 code
and assembled. The 8-bit registers are:
AX --> AH,AL
BX --> BH,BL
CX --> CH,CL
DX --> DH,DL
Flag Register
Flag register contains information reflecting the current status of a microprocessor.
It also contains information which controls the operation of the microprocessor.
There are five flag bits that are commonly tested during the execution of instructions
Sign Flag (Bit 7), SF: 0 for positive number and 1 for negative number.
Zero Flag (Bit 6), ZF: If the ALU output is 0, this bit is set (1); otherwise, it is 0.
Carry Flag (Bit 0), CF: It contains the carry generated during the execution.
Auxiliary Carry (Bit 4), AF: Depending on the width of ALU inputs, this flag bit contains the
carry generated at bit 3 (or, 7, 15) of the 8088 ALU.
Parity Flag (bit2), PF: It is set (1) if the output of the ALU has even number of ones;
otherwise it is zero.
Direction Flag
Direction Flag (DF) is used to control the way SI and DI are adjusted during the
execution of a string instruction
DF=0, SI and DI will auto-increment during the execution; otherwise, SI and DI auto-
decrement
Instruction to set DF: STD; Instruction to clear DF: CLD
Example:
Segments
Microprocessor and Microcontroller with 8085 and 8086
92
The offset is the distance in bytes from the start of the segment.
The offset is given by the IP for the Code Segment.
Instructions are always fetched with using the CS register.
The physical address is also called the absolute address.
Even addresses are on the low half of the data bus (D0-D7).
Odd addresses are on the upper half of the data bus (D8-D15).
A0 = 0 when data is on the low half of the data bus.
BHE = 0 when data is on the upper half of the data bus.
In maxmode, the 9 signals change their functions; the 8088 now requires the use of
the 8288 bus controller to generate memory and I/O read/write signals.
Maxmode systems are more complicated, but obtain the new signals that allow for
bus grants (e.g. DMA), and the use of an 8087 coprocessor.
HIGH
Microprocessor and Microcontroller with 8085 and 8086
96
Instruction Types
Data transfer instructions
String instructions
Arithmetic instructions
Bit manipulation instructions
Loop and jump instructions
Subroutine and interrupt instructions
Processor control instructions
Addressing Modes
Exceptions:
• String addressing
• Port addressing (e.g. IN AL, 79H)
For 80x86 family, directly moving data from one memory location to another
memory location is not allowed.
MOV[SI], [5000H]
When the size of data is not clear, assembler directives are used
MOV[SI], 0
Microprocessor and Microcontroller with 8085 and 8086
97
MOVDS, 1234H
PUSH (Source)
PUSHHF
POP (Destination)
POPF
String Instructions
String is a collection of bytes, words, or long-words that can be up to 64KBin length.
String instructions can have at most two operands. One is referred to as source
string and the other one is called destination string.
• Source string must locate in Data Segment and SI register points to the
current element of the source string.
• Destination string must locate in Extra Segment and DI register points to the
current element of the destination string.
— The prefix instruction makes the microprocessor repeatedly execute the string
instruction until CX decrements to 0 (During the execution, CX is decreased by one when the
string instruction is executed one time).
— For Example:
MOV CX, 5
REP MOVSB
By the above two instructions, the microprocessor will execute MOVSB 5 times.
{ CX = CX –1;
CX = CX –1; MOVSB;
MOVSB; OR gotoCheck_CX;
} end if
Microprocessor and Microcontroller with 8085 and 8086
100
String Instructions
MOVSB (MOVSW)
Move byte (word) at memory location DS:SI to memory location ES:DI and update SI
and DI according to DF and the width of the data being transferred.
It does not modify flags.
Example:
CMPSB (CMPSW)
Compare bytes (words) at memory locations DS:SI and ES:DI; update SI and DI
according to DF and the width of the data being compare.
It modifies flags.
Example:
SCASB (SCASW)
LODSB (LODSW)
STOSB (STOSW)
The displacement is the number that, when added to the IP, changes the IP to point
at the jump target. Remember the IP is pointing at the next instruction when this occurs.
The loop instructions perform several operations at one time but do not change any
flags.
LOOPNZ or LOOPNE -- loop while not zero or not equal: decrements CX and jumps if CX is
not zero or the zero flag ZF = 0.
LOOPZ or LOOPE -- loop while zero or equal: decrements CX and jumps if CX is zero or the
zero flag ZF = 1.
The conditional jump instructions often follow a compare CMP or TEST instruction.
These two instructions only affect the FLAG register and not the destination. CMP does a
SUBtract (dest - src) and TEST does an AND.
For example, if a CMP is followed by a JG (jump greater than), then the jump is taken
if the destination is greater than the source.Test is used to see if a bit or bits are set in a
word or byte such as when determining the status of a peripheral device.
Microprocessor and Microcontroller with 8085 and 8086
102
Conditional Jumps
The control word Register and counters are selected according to the signals on line A0 and
A1 as shown below :
A1 A0 Selection
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Register
BCD:
Microprocessor and Microcontroller with 8085 and 8086
104
Disadvantages
A lot of MPU time is wasted during looping to check the device status which may be
prohibitive in many situations.
Some simple devices may not have status signals. In such a case MPU goes on
checking whether data is available on the port or not.
Multiple Interrupts:
The MPU has one interrupt level and several I/O devices to be connected to it which
are attended in the order of priority.
The MPU has several interrupt levels and one I/O device is to be connected to each
interrupt level.
The MPU has several interrupt levels and more than one I/O devices are to be
connected to each interrupt level.
The MPU executes multiple interrupts by using a device polling technique to know
which device connected to which interrupt level has interrupted.
Microprocessor and Microcontroller with 8085 and 8086
108
Interrupts of 8085
On the basis of priority the interrupt signals are as follows:
• TRAP
• RST 7.5
• RST6.5
• RST5.5
• INTR
Interrupt Instructions
EI (Enable Interrupt): This instruction sets the interrupt enable Flip Flop to activate the
interrupts.
DI (Disable Interrupt): This instruction resets the interrupt enable Flip Flop and deactivates
all the interrupts except the non-maskable interrupt i.e. TRAP.
SIM (Set Interrupt Mask): This enables\disables interrupts according to the bit pattern in
accumulator obtained through masking.
RIM (Read Interrupt Mask): This instruction helps the programmer to know the current
status of pending interrupt.