Microprocessor 8086 Course
Microprocessor 8086 Course
See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/380131796
8086 COURSE
CITATIONS READS
0 207
1 author:
Monji Zaidi
King Khalid University
49 PUBLICATIONS 165 CITATIONS
SEE PROFILE
All content following this page was uploaded by Monji Zaidi on 27 April 2024.
Preface …
To achieve high performance at low dominant frequencies, Banias has been optimized to allow more
instructions to be executed per clock and to reduce the false prediction rate with advanced branch
prediction. Another notable improvement is the increase in the L2 cache to 1 MB (P3-M and P4-
M are only 512 KB), where most of the estimated 77 million transistors are used.
The first Intel Pentium D processor with two processing cores is on the market, officially ushering
in the multi-core era of x86 processors.
[1]
The Core microarchitecture desktop processor, whose core is codenamed Conroe and will be called
the Core 2 Duo/Extreme family, offers a 40% performance improvement over the previous Intel
Pentium D 960 (3.6 GHz) processor. . The power saving efficiency also reaches 40%, and the Core
2 Duo processor contains 291 million transistors.
2008: i7 processor
The next-generation desktop processor based on the new Nehalem architecture, "Core", named
the "Intel Core i7" series, is a 64-bit quad-core processor released by Intel in 2008. It follows the
x86-64 instructions and is based on the Intel Nehalem microarchitecture. Replaces Intel Core 2
series processors.
On April 24, 2012, Intel officially released the Ivy Bridge (IVB) processor. The 22nm Ivy Bridge
will double the number of execution units to a maximum of 24, which will naturally lead to another
leap in performance. Ivy Bridge adds integrated graphics with DX11 support. Additionally, the
new XHCI USB 3.0 controller shares four of these channels, providing up to four USB 3.0 ports
to support native USB 3.0. The processors are built using 3D transistor technology which cuts a
processor's power consumption in half.
[2]
In a microprocessor system as shown in figure 1.1 (Von Neumann Architecture), we find at least:
A microprocessor
A Read Only Memory (ROM) and a Random Access Memory (RAM)
Inputs/Outputs interface
All these devices are interconnected with 3 buses: Bidirectional data bus, Address bus and Control
bus
3.1.The microprocessor
This is the heart of the system. It is responsible for the following functions:
The role of memory is to store groups of binary digits (words) which are either instructions forming
a program, or data that the program needs. It is often broken down into:
ROM: Read Only Memory. Read-only memory, no writing. Its content is programmed
once for all by the manufacturer.
Advantage: low cost.
Disadvantage: requires production in very large quantities.
PROM: Programmable Read Only Memory. ROM programmable only once by the user.
EPROM: Erasable PROM, also called UVPROM. ROM electrically programmable with
a programmer and erasable by exposure to ultraviolet radiation.
[3]
Hard disk, USB disk, CDROMs … etc. are a storage devices and they are considered as secondary
memory.
The number of address lines depends on the memory capacity (size): n address lines allow
memory locations to be addressed: 8 address bits allow 256 (2 ) bytes to be addressed, 16 address
bits allow 65536 (2 ) to be addressed bytes (= 64 KB)...
= 2 ∗
[4]
= 2
3.3.Input-Output interfaces
Write: The microprocessor sends the write order and the data is stored in the interface
register.
Read: the circuit simply presents the device information on the data bus.
4. The Intel 8086 microprocessor (External look)
4.1.Physical description of 8086
The Intel 8086 microprocessor is a 16-bit microprocessor, which appeared in 1978. It is the first
microprocessor in the Intel 80x86 family (8086, 80186, 80286, 80386, 80486, Pentium, etc.). It
comes in the form of a 40-pin DIP (Dual In-line Package) as shown in the figure 1.3.
[5]
Figure 1.4 the 8086 pin assignments in min and max mode
To specify each category of input-output signals, we represent the 8086 differently as shown by
the figure 1.5.
[6]
Input of the clock signal which clocks the operation of the microprocessor. This signal comes from
a clock generator: the 8284.
Since it needed numerous extra circuits to generate the clock in an 8086/8088-based system, the
8284A is a crucial auxiliary part of the 8086/8088 microprocessor. Clock generation system is
given by the figure 1.6.
RESET
Microprocessor reset input. When this input is set high for at least 4 clock periods, the
microprocessor is reset: it will execute the instruction located at address FFFF0H (bootstrap
address). The RESET signal is provided by the clock generator.
AD0 to AD15
Lower-order address buses are data multiplexed. The symbol A is used in place of AD when
transmitting memory addresses via AD lines, such as A0-A15.
The symbol D is used in place of AD when data are transmitted throughout AD lines, such as D0-
D7, D8-D15, or D0-D15.
A16-S3 to A19-S6
[7]
A16-S3, A17-S4, A18-S5, and A19-S6 Bus with high order address. They are are multiplied with
status signals.
S0 to S2
Status signals
Machine Cycle
0 0 0 Interrupt acknowledge
0 1 1 Halt
1 0 0 Code access
1 1 1 Passive-Inactive
ALE
(Address Latch Enable): This signal is an active pulse during a time T1, it indicates that the
information circulating in bus A/D is an address.
M/
[8]
Data Enable, indicates that data is circulating on the A/D bus (equivalent to ALE for data)
DT/
Synchronization input with memory. This signal also comes from the clock generator.
MN/
Minimum Mode: MN/ = 1 : The 8086 works autonomously, it generates itself the
control bus ( , , ...)
Maximum Mode: MN/ = 0 : These control signals are produced by a bus controller,
the 8288. This mode makes it possible to create multiprocessor systems
NMI and INTR
Interrupt request inputs. INTR: normal interrupt, NMI (Non Maskable Interrupt): priority
interrupt.
[9]
Transferred bytes
0 both bytes (full word): 15 − 0
0
1 Significant byte (odd address): 15 − 8
0
0 lower byte (even address): 7 − 0
1
1 no bytes
1
4.4.Basic Connections
GND: connect to 0V.
VCC: connect to 5V.
MN / MX: connect to 5V (minimum mode).
NMI and INTR: connect to 0V (no support for interrupts).
CLK: connect to the CLK output of the clock generator.
HOLD: connect to 0V (no direct memory access).
TEST: connect to 0V (no wait for co-processors).
READY: connect to 5V (no wait cycles for slow devices).
RESET: connect to zero of clock generator output.
Note:
[10]
[11]
You can use 8-bit or 16-bit data with the 8086. The 8086 accesses memory with a 20-bit
address and 1/0 devices with a 16-bit address.
7. What are the interrupts of 8086?
NMI and INTR are the 8085/6 interrupts. NMI is a non-maskable interrupt, and INTR is
a generic maskable interrupt.
8. What is Software interrupts?
Program instructions are contained in software interrupts. These instructions are added
to a program at the appropriate places. If a software interrupt instruction is encountered
while a program is running, the processor will carry out an interrupt service routine.
9. What is Hardware interrupt?
A processor interrupt is referred to as a hardware interrupt if it is caused by a suitable
signal at the interrupt pin.
10. Why crystal is a preferred clock source?
Due to its great stability, high QF (Quality Factor), and frequency that remains constant.
The majority of the time, crystal is employed as a clock source.
11. How clock signal is generated in 8086? What is the maximum internal clock
frequency of 8086?
There is no on-chip clock generating circuit in the 8086. Therefore, the CLK pin of 8086 is
connected to the clock generator chip, 8284. For internal use, the 8284-supplied clock signal
is split by three. The 8086's highest internal clock frequency is 5MHz.
12. What is the use of HLDA
The acknowledgment signal for HOLD is HLDA. It denotes the presence or absence of the
HOLD signal. The control signals for DMA operations are HOLD and HLDA.
13. What is the main use of ready pin?
The CPU uses READY to determine if a peripheral is prepared to receive or send data. An
analog to digital converter, LCD display, or any other device can be considered a peripheral.
The READY pin is used to link these devices to the microprocessor. The peripheral is
prepared for data transfer if READY is high. In the event that it doesn't, the CPU waits
until READY reaches high.
14. What is the need for timing diagram?
[12]
The timing diagram provides information regarding the status of various signals, when a
machine cycle is executed. The knowledge of timing diagram is essential for system
designer to select matched peripheral devices like memories, latches, ports, etc., to form a
microprocessor system.
15. Define machine cycle.
A machine cycle is the amount of time needed to do one I/O, memory access, or request
acknowledgment from outside the system. There could be three to six T-states in this cycle.
16. Why interfacing is needed for 1/0 devices?
I/O devices are often slowly devices. As a result, the microprocessor's speed and the speed
of I/O devices are not equal. Thus, an interface is offered between I/O devices and the
system bus.
17. What does memory-mapping mean?
The process of connecting memory to a microprocessor and assigning addresses to each
memory location is known as memory mapping.
18. What is DMA?
DMA is the term for the direct data transmission between an I/O device and memory.
19. How DMA is initiated?
The I/O device will notify the DMA controller with a DMA request signal whenever it
needs a DMA transfer. The processor receives a HOLD request from the DMA controller.
At the conclusion of the current instruction execution, the processor will push its tri-stated
pins to a high impedance state in response to a HOLD request. It will then send an
acknowledgement signal to the DMA controller. DMA transfer will now be carried out by
the DMA controller.
20. Which of the following is not an 8086 maximum mode signal?
(A) LOCK
(B) S0
(C)ALE
(D) QS0
Answer: C (Detailed Solution: ALE is a minimum mode signal)
[13]
21. What is the maximum capacity of the memory that can be interfaced to the
microprocessor which contains 20 address lines?
a.) 64 KB
b.) 1 MB
c.) 64 MB
d.) 1 GB
Answer: B
Detailed Solution: = 2 = 1048576 = 1
22. The size of ALU in 8086 is
a.) 8 bit
b.) 16 bit
c.) 24 bit
d.) 32 bit
Answer is B
23. These are two ways in which a microprocessor can come out of Halt state.
(A) When hold line is a logical 1.
(B) When interrupt occurs and the interrupt system has been enabled.
(C) When both (A) and (B) are true.
(D) When either (A) or (B) are true.
Answer is (A)
[14]
The diagram of the internal structure (Figure 2.1) shows two units, one which executes the
instructions (EU, Execution Unit) with its arithmetic and logic unit (UAL) and its registers; the
other which ensures the connection with the outside world (BIU, Bus Interface Unit) generates
the addresses using an address generation unit and reads the instructions which it places in a
queue (Queue), of 6 bytes for the 8086 and 4 for the 8088.
[15]
Both units operate simultaneously, resulting in an acceleration of the program execution process
(operation according to the pipeline principle).
Four groups of 14 registers make up the 8086 microprocessor:
1.2.General registers: 4 registers of 16 bits.
=( , ) : The Accumulator it is used (not limited to) for the following purposes:
General use:
=( , ) : The Base Register it is used (not limited to) for the following purposes:
General use,
=( , ) : The Count Register it is used (not limited to) for the following purposes:
General use.
=( , ) : The Data Register it is used (not limited to) for the following purposes:
General use.
[16]
These register (AX, BX, CX and DX) can also be considered as 8 registers on 8 bits. They are used
to temporarily hold data.
Used for stack access. Points to the head of the battery. By default, its offset is relative to SS
BP: Base Pointer, used to address data on the stack. Addressing as base register, (By
default, its offset is relative to SS).General purpose
1.4.Index registers: 2 registers of 16 bits.
SI: Source Index. Addressing as index register, (By default, its offset is relative to DS).
Some data movement instructions use it as an index of the source operand. The destination operand
being indexed by DI. General purpose.
DI: Destination Index. Addressing as index register, (By default, its offset is relative to
DS). Some data movement instructions use it as an index of the destination operand. The
destination operand being indexed by SI. General purpose.
1.5.Segment registers: 4 registers of 16 bits.
These registers are combined with the offset registers to form the addresses. A memory location is
identified by an address of the form Segment Register : Offset Register. We place the segment
register at the start of a 64Kb memory zone, then we vary the offset register which specifies the
relative address in relation to this position.
Defines the start of program memory. The addresses of the different program instructions are
relative to CS
Start of data memory in which all data processed by the program is stored
Start of the stack. The stack is a memory area managed in a particular way. It is organized like a
stack of plates. We always place and remove the plates on the top of the stack. A single offset register
[17]
is therefore sufficient to manage it, the stack pointer (SP). It is called a LIFO (Last IN, First Out)
stack.
Stack data: save data on (top) of the stack (push instruction… soon)
Unstack data: remove data (from the top) of the stack (pop instruction… soon)
[18]
Flag register: The 8086 microprocessor has status indicators, which are updated by the
execution unit. The state of these indicators depends on the result of the arithmetic and
logical operation that has just taken place.
Figure 2.3 gives the location of the inductors in the flag register or (Status flag)
Carry Flag (CF): After performing any operation on an 8086 microprocessor, the carry flag will
only be set if a carry is created from the MSB of the result.
Parity Flag (PF): the number of 1s in the binary data determines parity. Two different kinds of
parity exist:
Even Parity: The state in which all of the binary data's 1s are even.
When the binary data has an odd number of 1s, it is said to have odd parity.
If there is even parity in the data following the execution of the instruction, the PF is set for the
flag. The flag is reset if not.
Auxiliary Carry Flag (AF): In an arithmetic operation, when the carry is generated from bit D3
to D4, the auxiliary carry flag is set to 1. (Starting from bit D0)
Zero Flag (ZF): The zero flags are set to 1 if an appropriate operation (either logical or arithmetic)
on the instructions yields a zero result. If not, it stays reset.
[19]
Sign Flag (SF): The sign flag is set to 1 if the result of any arithmetic or logic operation carried
out in the provided instruction is negative. If not, the sign flag is left reset in the event of a favorable
outcome.
Overflow Flag (OF): After every arithmetic or logic operation, this flag will be set if the register
overflows with data. This occurs when the carry is received in MSB but the carried out bit cannot
be stored in the register.
AL=0Fh 0 0 0 0 1 1 1 1
BL=08h 0 0 0 0 1 0 0 0
AL+BL=17h CF = 0 0 0 0 1 0 1 1 1
CF=0, OF=0
Both operands and the result are positive. PF=1, ZF=0, SF=0, AF=1
The integers 0 to 255 (11111111 in binary) can be expressed with 8 bits. Negative integers can be expressed in binary
format using signed magnitude, for example. Rather than showing the number, the most important element, which is
on the left, is utilized to indicate if the number is positive or negative.
We can generate 256 combinations (ranging from 0 to 255) using an 8-bits number system. Positive numbers are
represented by the first 128 combinations (0 to 127) and negative numbers by the next 128 combinations (128 to 255).
Unsigned numb (decimal) Its binary form Its hex form Signed numb (decimal)
0 00000000 00 +0
1 00000001 01 +1
2 00000010 02 +2
… … …
[20]
… … … …
254 11111110 FE -2
255 11111111 FF -1
AL=0Fh 0 0 0 0 1 1 1 1
BL=F8h 1 1 1 1 1 0 0 0
AL+BL=07h CF = 1 0 0 0 0 0 1 1 1
[21]
(-8) is the signed form of 1111 1000 obtained using the concept of figure 2.4
AL=4Fh 0 1 0 0 1 1 1 1
BL=40h 0 1 0 0 0 0 0 0
AL+BL=8Fh CF = 0 1 0 0 0 1 1 1 1
CF=0, OF=1, the result and operands have different sign bits.
To guide the microprocessor for certain tasks, the control flags are employed. A control flag can be
of three types:
Trap Flag (TF): This flag is used of we need single-step debugging in our code. If the TF is set,
then the execution will be done step by step. Otherwise, the free-running operation will be done.
Interrupt Flag (IF): This flag is used to enable the Interrupt. The microprocessor is capable of
handling interrupts only if this flag is in the set mode. Otherwise, any interrupt raised while the
execution of the instructions will not be handled by the microprocessor.
Direction Flag (DF): This flag is used for string operations. If this flag is set, the string will be
read from higher-order bits to lower order bits and vice versa
[22]
The 8086 has 20 address bits, so it can address 2 bytes or 1 MB. The address of the first memory
location is 0000 0000 0000 0000 0000 (00000h), the last case is 1111 1111 1111 1111 1111 1111
(FFFFFh).
The problem that arises is how to represent these addresses within the µP since the registers are
only 16 bits, i.e. 4 maximum digits in hexadecimal. The solution adopted by Intel was as follows:
Since with 16 bits we can address 2 bytes = 65535 bytes = 64 KB, the total addressable memory
of 1 MB is divided into pages of 64 KB called segments. (It seems like pages)
We then use two registers to address a given memory location, A register to address the segment
which is called segment register and a register to address inside the segment by addressing
register or offset.
An address is always in the form Segment : Offset
As an example, let's divide the memory into 16 non-overlapping segments. (It seems like 16 pages
without intersection to cover all the physical memory:64 ∗ 16 = 1 )
[23]
Consider the address memory location 20350, called physical address or linear address. This
memory location is located in segment 2, its address relative to this segment is 350, and we can
therefore reference this location by the pair: ∶ = :
[24]
Now there is the problem of representing this address within the CPU because 16-bits registers
can only contain 4 digits. If there is no problem representing 350 in an offset register, we cannot
represent 20000 in a segment register. The solution adopted by Intel is as follows:
In the segment register, we write the segment address without the least significant digit
In the addressing (offset) register we write the relative address in the segment
To calculate the absolute address that will be sent on the 20-bits address bus, the CPU adds
the two registers after shifting the segment register one digit (4 bits) to the left.
[25]
So:
In our example, the address of the memory box considered becomes 2000:350, i.e.:
Segment = 2000
Offset = 350
= ∶ = :
We are using here the code segment and it relative pointer IP (see figure 2.2). The concept is the
same for other segment register except the relative pointer will change.
To execute a program, the 8086 fetches the instructions from the code segment.
The logical address of an instruction consists in CS (code segment) and IP (the instruction pointer)
= :
Answer
[26]
Answer
The CPU uses the stack, which is part of RAM, to temporarily store data. Since there are only a
few registers in the CPU, this storage space is critical.
[27]
To access the stack in the memory, SP (stack pointer) and SS (stack segment) must be loaded.
All CPU registers, with the exception of segment registers and SP, can be loaded from and
transferred to the stack.
In a stack segment, the offset address in the SP register and the segment address in the SS register
are used to indicate the logical address.
SS : SP
Copy the content of the source (16 bits) into the stack
SP register is decremented by 2
Example 1
After the following instruction is executed, what are the contents of AX, the top of the stack, and
SP given that SP=1456H?
Answer:
Note that in 80x86 the lower byte of the register is stored to the lower address. (Little Endian
Convention)
[28]
Example 2
You are given SP=1236H, AX=24B6H, DI=85C2H, and DX=5F93H, show the contents of the
stack and SP as each of the following instructions is executed.
POP AX
POP DI
POP DX
Answer:
After pushing data from registers to the stack, registers AX, DI and DX stay the same. PUSH
seems like a copy from - to (not cut)
Loading the contents of the stack into the CPU register is called a pop.
[29]
SP register is incremented by 2
Example 1
Assume that SP=134AH and the illustration on the left shows the content of the top of the stack.
What will be the content of AX and SP after the execution of the following instructions?
SUB AX, AX
POP AX
Answer:
Note that in 80x86 the byte in the Low address goes into the low byte. The byte in the high address
goes into the high byte. (Little Endian Convention)
Note:
Example 2: Assume that the stack is shown below, and SP=18FAH, show the contents of the
stack and registers as each of the following instructions is executed.
[30]
SUB CX, CX
SUB DX, DX
SUB BX, BX
POP CX
POP DX
POP BX
Answer:
Figure 2.12 Impact of three pop instructions on the SS, destination and SP
Note:
When pushing data from SS to destination, this data is erased from SS.
If the stack pointer (SP) = 3499, data index (DI) = 1A5E and BX = 2E4C, what are the contents
of SP, DI and BX after the execution of the following instructions. (Assume the processor is 8086).
PUSH DI
PUSH BX
[31]
POP DI
POP BX
Answer:
To do this, proceed like figures 2.10 and 2.12, you will get the following results
POP BX
[32]
1. Definition
Different methods for accessing an address to a specific data are provided to a processor by the
addressing mode. The specified function is carried out on the data when an instruction is executed
by an 8086 processor. The memory location contains operated data. There are many ways for
defining a data address. We refer to these methods as addressing modes.
Addressing mode can be classified according to the following diagram given by figure 3.1.
This mode relates to data transfer operations, i.e., data is moved between registers or from memory
to the 8086 processor's internal registers.
[33]
Program memory addresses are used throughout numerous activities in this mode.
Example: The code execution control of the JMP AX instruction jumps to the current code segment
location, which is addressed by the contents of the AX register.
Stack registry procedures are involved in this mode. An example of an instruction that copies the
contents of the AX register to the stack is PUSH AX.
When we perform an instruction between a register and data located in memory, it is the register
that determines the size of the operation.
If the register is a simple register (8 bits), the operation will be carried out with a single memory
location.
Figure 3.2 Instruction size when moving one byte to memory location
[34]
If the register is 16 bits (2 bytes), the operation will be carried out with two memory locations
Note that it is the lower part of the register which is processed first, and this in both directions
When we perform an operation between a constant and a memory location, there is ambiguity. The
processor does not know whether to consider the constant on 8 bits or on 16 bits. We must use the
BYTE and WORD prefixes to specify the number of bytes to move:
Figure 3.4 Instruction size when moving a constant (byte/word) to memory locations
[35]
Example
MOV [BX], AX
Note: We will use MOV instruction to explain all the data addressing modes.
[36]
Example
4.2.Immediate addressing
Immediate addressing transfers the source, an immediate byte or word data, into the destination
register. Immediate data means constant data, whereas data transferred from a register or memory
location are variable data.
Example
[37]
4.3.Direct addressing
In this mode, one operands references a memory location and other operand references a register.
Example 1
The square brackets around 6107h denotes the content of the memory. Here, data resides in a
memory location in the data segment, whose physical address may be computed using 6107 h as
the offset address and content of DS (see next table) as segment address. The physical address,
here, is:
ℎ = ∗ 10 ℎ + 6107 ℎ.
In MOV AX, [6107 h], the data located at [ ∗ 10 ℎ + 6107] will be moved to AX
MOV [6107 h], CL, the content of CL will be moved to the address [ ∗ 10 ℎ + 6107]
Important: the following table gives each addressing mode with its relative operands
and default segment
Example 2
Find the physical address of the memory location and its content after the execution of the following
instructions, assuming that DS = 1512h
MOV [6789], AL
Answer:
[38]
Second, it’s clear referring to the next table that the addressing mode here is the direct addressing
mode. So the default segment is DS and the offset is 6789. We are needed to calculate the physical
address at which we will move the content of the register AL.
Hence the memory location having the address 1B8A9 will contain the content of AL which is B2h
[BX] DS
[DI] DS
[39]
[BP] SS
[BX] + displacement DS
5. Based relative addressing
[BP] + displacement SS
[DI] + displacement DS
6. Indexed relative addressing
[SI] + displacement DS
[BX][SI] + displacement DS
[BX][DI]+ displacement DS
7. Based Indexed relative addressing
[BP][SI] + displacement SS
[BP][DI] + displacement SS
[40]
Example
Assume that DS = 1120, SI = 2498, and AX = 17FE. Shown the content of the memory location
after the execution of MOV [SI], AX
Answer:
Make attention here!! We are moving 16 bits (AX) to a certain memory location having the size
of only 8 bits!! We proceed then as follow
From the form of the instruction MOV [SI], AX and referring to the table we understand that we
are using the Register indirect addressing mode. The used offset is SI. So DS is the default segment
used to generate the physical address.
Physical address = DS ∗ 10 h + SI
ℎ = 11200 + 2498 = ( )
The memory location addressed by can store only 8 bits. Don’t forget we have to move
AX=17FE (16 bits = 8bits + 8 bits). We need then, another memory location to save (store) the
second half of AX. In 8086 microprocessor (indirect addressing mode) the solution is:
ℎ ( )+
Finally:
[41]
4.5.Based-Relative addressing
In the based relative addressing mode, base registers BX and BP as well as displacement
value are used to generate the physical address.
The default segment used to calculate the physical address are DS when the using BX and
SS when using BP
Example
[42]
Example
Here, No need for going to the physical address +1. The destination (CL) is 8 bit size.
Numerical example
Assume that: DS=4500, SS=2000, BX=2100, SI=1486, DI=8500, BP=7814 and AX=2512
Show the exact physical memory location when AX is stored in each of the following. Data are in
hexadecimal
Answer:
[43]
By combining based and indexed addressing mode, a new addressing mode is generated called the
based indexed addressing mode.
In this mode, one base register and one index register are used to generate the physical address
[44]
To tell the assembler to use the logical segment name for a given segment, we use the ASSUME
directive. There are just four physical segments that the 8086 uses for direct operation: a code
segment, a data segment, a stack segment, and an additional extra segment.
Examples
This instructs the assembler to treat the logical segment CODE, which contains the program's
instruction instructions, as a code segment.
This instructs the assembler to look for data in the logical segment DATA for any instruction that
references data in the data segment.
Example
My-constant EQU A7h; My-constant can be used in many places in the program
[45]
Example
PRICE DB 49h, 98h, 29h;Declare an array of 3 bytes, named as PRICE and initialized to the
given value.
NAME DB ’A-C=EF’; declare an array of 6 bytes and initialize with ASCII code for letters and
symbols
DATA1 DB FFh, FFh, FFh, FFh, FFh; Fill 5 bytes with FFh
DATA2 DB 5DUP (FFh); same as DATA1, Fill 5 bytes with FFH (it saves time and typing)
TEMP DB 100 DUP (?); Set 100 bytes of storage in memory and give it the name as TEMP, but
leave the 100 bytes uninitialized (empty). Program instructions will load values into these
locations.
The DW directive is used to define a variable of type word or to reserve storage location of type
word in memory.
Example
Multiplexer DW 1A2Bh; this declares a variable of type word and named it as Multiplexer. This
variable is initialized with the value 1A2B h when it is loaded into memory to run.
Table DW ABCDh, 5678h, FFFFh; this declares an array of 3 words and initialized with specified
values.
Table2 DW 100 DUP (0); Reserve an array of 100 words of memory and initialize all words with
The DD directive is used to allocate memory locations that are 4 bytes (two word)
Example:
[46]
DATA4 DD C1h, B2h, 84h, F1h ; allocation of 16 bytes to store specified data
Is used to allocate memory 8 bytes (4 words) in size. This can be used to represent any variable up
to 64 bit wide
END Directive
END directive is placed after the last statement of a program to tell the assembler that this is the
end of the program module
ENDP Directive
ENDP directive is used along with the name of the procedure to indicate the end of a procedure to
the assembler
Example:
ENDS Directive
This ENDS directive is used with name of the segment to indicate the end of that logic segment.
Example:
CODE SEGMENT;
[47]
Hear it start the logic segment containing code. Some instructions statements to perform the
logical and or arithmetic operations ….
INCLUDE Directive
This INCLUDE directive is used to insert a block of source code from the named file into the
current source module.
PTR operator
Example:
INC [BX]; this instruction will not know whether to increment the byte pointed by BX or a word
pointed by BX.
Here is the Code written on assembly language for 8086 microprocessor. This code find if the
number is positive or negative.
[48]
4. Instructions Sets
4.1. Data transfer instructions
MOV destination, Source
MOV Reg1, Reg2; copy Reg2 in Reg1
MOV Reg, Mem; copy Mem in Reg
MOV Mem, Reg; copy Reg in Mem
MOV Size Mem, immediate; copy immediate in a memory location (Size = byte or Word)
Example
[49]
SP decremented by 2
PUSH Reg(16)
PUSH Word [Address]
PUSH immediate, not allowed
PUSH Reg (8), not allowed
POP Reg (Reg should be 16 bit size)
SP incremented by 2
Exchanges the Source operand with the Destination operand. Impossible on segment.
Example
For the figure 4.2. What is the result of executing the following instruction?
First, we need to determine the physical address, from which the data will be exchanged.
[50]
From the instruction, it is sample right now to determine the addressing mode and the default
segment as described in chapter 3
This instruction determines the offset of the variable or memory location named as the source and
puts this offset in the indicated 16-bit register. LEA does not affect any flag.
Example
[51]
This instruction loads new values into the specified register and into the DS register from four
successive memory locations. The word from two memory locations is copied into the specified
register and the word from the next two memory locations is copied into the DS registers. LDS
does not affect any flag.
LDS BX, [4326] Copy content of memory at displacement 4326H in DS to BL, content of
4327H to BH. Copy content at displacement of 4328H and 4329H in DS to DS register.
LDS SI, SPTR Copy content of memory at displacement SPTR and SPTR + 1
LES Register, Memory address of the first word
This instruction loads new values into the specified register and into the ES register from four
successive memory locations. The word from the first two memory locations is copied into the
specified register, and the word from the next two memory locations is copied into the ES register.
LES does not affect any flag.
[52]
LES BX, [789AH] Copy content of memory at displacement 789AH in DS to BL, content
of 789BH to BH, content of memory at displacement 789CH and 789DH in DS is copied
to ES register.
LES DI, [BX] Copy content of memory at offset [BX] and offset [BX] + 1 in DS to DI
register. Copy content of memory at offset [BX] + 2 and [BX] + 3 to ES register.
XLAT
The XLAT (translate) instruction converts of the AL register into a number stored in a
memory table.
This instruction performs the direct table lookup technique often used to convert one code
to another.
An XLAT instruction first adds the contents of AL to BX to form a memory address within
the data segment. It then copies the content of this address into AL.
This is the only instruction that adds an 8-bit number to a 16-bit number.
[53]
IN Accumulator, Port
OUT Port, Accumulator
To communicate with an external peripheral, the accumulator is AL for the transfer of a
byte.
To communicate with an external peripheral, the accumulator is AX for the transfer of a
word.
When the port number is byte (0 to 255 in/out combination), it can be an immediate value
(included in the instruction itself) : Fixed-port addressing
When the port number is word (0 to 64K in/out combination), it must be loaded in DX
Variable-port addressing
Example:
IN AL, 76H; 8 bits are input to AL from I/O port 76H (fixed port addressing)
IN AL, DX; 8 bits are input to AL from I/O port DX (variable port addressing)
OUT 51H, AX; 16-bits are output to I/O port 51H from AX (fixed port addressing)
OUT DX, AL; 8-bit data are output to I/O port DX from AL (variable port addressing)
[54]
After the addition, the AL register (destination) will contain 00h and the flags are as follows:
ZF = 1 the result of the instruction is zero (for the 8 bit, don’t consider the last carry)
[55]
Write an ALP to calculate the total sum of 5 bytes of data. Each data does not make more than
255 (FFh). The decimal data are as follows:
Write an ALP to calculate the total sum of 5 words of data. Each data does not make more than
65555 (FFFFh). The decimal data are as follows:
[56]
[57]
SBB TABLE [BX], CX; Subtract CX and status of CF from word in memory at effective
address TABLE [BX].
Assuming that the 8086 is executing a simple subtract instruction, we can summarize the steps
of the hardware CPU in executing the SUB instruction for unsigned numbers as follows:
SUB AL, BH
AL = 3FH = 00111111
BH = 23H = 00100011
The programmer must look at the carry flag (not the sign flag) to determine if the result is positive
or negative
If CF=1 the result is negative and the destination has the second complement of the result (SUB
result). Normally the result is left in second complement, but the NOT and INC instructions can
be used to change it.
[58]
From the SUB instruction shown above, the CF should be 1. (With respect to CPU steps)
The result is then negative, so the result will be: Minus (2’s (1101 1110)) = - 34 = -22H
[59]
After the SUB instruction AX=62FA-963B=CCBF and carry flag is set (=1). Since CF=1, when
the SBB is executed AX=0625-0412-1-212, therefore the result stored in RESULT is 0212CCBF
MUL Source
MUL BH; Multiply AL with BH; result in AX
MUL CX; Multiply AX with CX; result high word in DX, low word in AX
MUL BYTE PTR [BX]; Multiply AL with byte in DS pointed to by [BX]
MUL FACTOR [BX]; Multiply AL with byte at effective address FACTOR [BX], if it is
declared as type byte with DB. Multiply AX with word at effective address FACTOR [BX],
if it is declared as type word with DW.
MOV AX, MCAND_16; Load 16-bit multiplicand into AX
MOV CL, MPLIER_8; Load 8-bit multiplier into CL
MOV CH, 00H; Set upper byte of CX to all 0’s
MUL CX; AX times CX 32-bit result in DX and AX
IMUL Source
IMUL BH; Multiply signed byte in AL with signed byte in BH; result in AX.
IMUL AX; Multiply AX times AX; result in DX and AX
CBW
CBW (Convert Byte to Word) performs an extension of AL into AH. We write the content of AL
in AX respecting the sign (MSB of AL)
If AL contains a positive number (MSB=0), we complete with 0s to obtain the 16-bit representation
of AX
[60]
DIV Source
DIV BL; Divide word in AX by byte in BL; Quotient in AL, remainder in AH
DIV CX; Divide down word in DX and AX by word in CX; Quotient in AX, and remainder
in DX.
IDIV Source
IDIV BL; Signed word in AX/signed byte in BL
IDIV BP; Signed double word in DX and AX/signed word in BP
IDIV BYTE PTR [BX]; AX / byte at offset [BX] in DS
INC Destination
INC BL; Add 1 to contains of BL register
INC CX; Add 1 to contains of CX register
INC BYTE PTR [BX]; Increment byte in data segment at offset contained in BX.
INC WORD PTR [BX]; Increment the word at offset of [BX] and [BX + 1] in the data
segment.
DEC Destination
DEC CL; Subtract 1 from content of CL register
DEC BP; Subtract 1 from content of BP register
DEC BYTE PTR [BX]; Subtract 1 from byte at offset [BX] in DS.
DEC WORD PTR [BP]; Subtract 1 from a word at offset [BP] in SS.
DEC COUNT; Subtract 1 from byte or word named COUNT in DS. Decrement a byte if
COUNT is declared with a DB; Decrement a word if COUNT is declared with a DW.
CMP Destination, Source
AF, OF, SF, ZF, PF, and CF are updated by the CMP instruction. For the instruction
CMP destination, source the values of CF, ZF, and SF will be as follows:
[61]
This instruction ANDs the byte / word in the specified source with the byte / word in the
specified destination. Flags are updated, but neither operand is changed. The test instruction is
often used to set flags before a Conditional jump instruction.
TEST CL, BL; AND CL with BL. No result stored; Update PF, SF, ZF.
TEST AX, 000AH; AND AX with immediate number 000AH; No result stored; Update
PF, SF, ZF
TEST BP, [BX] [DI]; AND word are offset [BX] [DI] in DS with word in BP. No result
stored. Update PF, SF, and ZF
4.3. Logic instructions
NOT Destination
Force a bit to 0:
[62]
To force a bit to 0 without modifying the other bits, we use the logical operator AND and these
properties:
OR Destination, Source
OR BH, DL; DL ored with BH, result in BH, DL not changed
OR BP, SI; SI ored with BP, result in BP, SI not changed
Forcer un bit à 1 :
Force a bit to 1: To force a bit to 1 without modifying the other bits, we use the logical operator
OR and these properties:
1 0 1
1 1 0
[63]
XOR CL, BH; Byte in BH exclusive-ored with byte in CL. Result in CL. BH not changed.
XOR BP, DI; Word in DI exclusive-ored with word in BP. Result in BP. DI not changed.
Invert a bit:
To invert the value of a bit without modifying the other bits, we uses the XOR logical operator
and these properties:
Bit XOR 1 =
A logical shift fills the newly created bit position with zero. If we do a single logical right shift on
11001111, it becomes 011001111.
An arithmetic shift is filled with a copy of the original number’s sign bit. If we do a single
arithmetic right shift on 11001111, it becomes 11100111.
[64]
SAL Destination, Count (Shift Arithmetic Left) is identical to the SHL instruction.
SAR DX, 1; Shift word in DI one bit position right, new MSB = old MSB
SAR reg, imm8
[65]
ROL AX, 1; Rotate the word in AX 1 bit position left, MSB to LSB and CF
ROL AX, 1; Rotate the word in AX 1 bit position left, MSB to LSB and CF
MOV CL, 04H; Load number of bits to rotate in CL
ROL BL, CL; Rotate BL 4 bit positions
MOV AL, 40H; AL = 01000000b
ROL AL, 1; AL = 10000000b, CF = 0
ROL AL, 1; AL = 00000001b, CF = 1
ROL AL, 1; AL = 00000010b, CF = 0
ROR Destination, Count
ROR BL, 1 Rotate all bits in BL right 1 bit position LSB to MSB and to CF
ROR reg, imm8
ROR mem, imm8
ROR reg, CL
ROR mem, C L
[66]
JMP ABC
This instruction fetches the next instruction from address at label ABC.
CLC
(Clear Carry), put CF at 0
STC
(Set Carry) , put CF at 1
CMC
(Complement) , put CF at its complement
JAE / JNB / JNC
(jump if above or equal / jump if not below / jump if no carry)
JB / JC / JNAE
[67]
[68]
LOOPNE / LOOPNZ
(Loop while cx ≠ 0 and zf = 0)
……………….
[69]
1. Introduction
The 8086 microprocessor operates faster than the peripheral devices. PPI establishes a connection
between peripheral devices and microprocessors.
8255A has:
Three I/O ports are available (Port A, Port B, and Port C (Upper and Lower))
Three operating modes (will be discussed with more details in next section)
Mode 0
Mode 1
Mode 2
[70]
The block diagram (In/Out pins) of the 8255A is given by the figure 5.3
2. Internal Architecture
[71]
The C port is divided into two high C port and low C port
RD WR CS Read operation
0 0 0 1 0 =
0 1 0 1 0 =
1 0 0 1 0 =
RD WR CS Write operation
0 0 1 0 0 =
0 1 1 0 0 =
1 0 1 0 0 =
1 1 1 0 0 =
X X X X 1 =ℎ ℎ ( )
X X 1 1 0 =ℎ ℎ ( )
[72]
The process of establishing inter relation between slower peripheral device and microprocessor is
called handshaking.
8255-based devices performs handshaking using some handshaking signals like, Strobe Input
(STB), Acknowledged (ACK), Input Buffer Full (IBF), Output Buffer Full (OBF).
(Strobe Input): A ‘‘low’’ on this input loads data into the input latch.
IBF (Input Buffer Full): A ‘‘high’’ on this output indicates that the data has been loaded
into the input latch; in essence, an acknowledgement. IBF is set by input being low
and is reset by the rising edge of the input.
INTR (Interrupt Request): A ‘‘high’’ on this output can be used to interrupt the
CPU when an input device is requesting service. INTR is set by the is a ‘‘one’’, IBF
is a ‘‘one’’ and INTE is a ‘‘one’’. It is reset by the falling edge of . This procedure allows
an input device to request service from the CPU by simply strobing its data into the port.
INTE A Controlled by bit set/reset of PC4.
INTE B Controlled by bit set/reset of PC2
(Output Buffer Full): The output will go ‘‘low’’ to indicate that the CPU has
written data out to the specified port. The will be set by the rising edge of the
input and reset by Input being low.
[73]
(Acknowledge Input): A ‘‘low’’ on this input informs the 82C55A that the data from
Port A or Port B has been accepted. In essence, a response from the peripheral device
indicating that it has received the data output by the CPU.
INTR (Interrupt Request): A ‘‘high’’ on this output can be used to interrupt the CPU
when an output device has accepted data transmitted by the CPU. INTR is set when
is a ‘‘one’’, is a ‘‘one’’ and INTE is a ‘‘one’’. It is reset by the falling edge of .
INTE A Controlled by bit set/reset of PC6.
INTE B Controlled by bit set/reset of PC2.
[74]
3.2.2. Mode 1
Used for handshake input/output operation.
Port B is initialized in mode 1 for either input or output, Pins PC0, PC1 and PC2 function
as handshake lines.
Port A can also be configured as input or output in mode 1. But handshake signal pins are
not same for input and output mode as like Port B.
If port A is initialized in mode 1 as handshake input port, then pins PC3, PC4 and PC5
function as handshake signals. (PC6 and PC7 are available for using as input lines or
output lines)
If port A is initialized as handshake output port, then PC3, PC6 and PC7 function as
handshake signals. (PC4 and PC5 are available for using as input or output lines)
[75]
3.2.3. Mode 2
Only port A can be initialized in mode 2.
In mode 2, port A can be used for “bi-directional handshake” data transfer i.e. data can be
input or output on the same eight lines.
Pins PC3, PC4, PC5, PC6, PC7 used as handshake lines for port A.
Port B is operating in either mode 0 or mode 1.
If port B is in mode 0, then PC0, PC1 and PC2 used for I/O.
If port B is in mode 1, then PC0, PC1 and PC2 used as handshake lines.
[76]
4. 8255 programming
The format as well as the choice of modes is made from the following control word:
[77]
5. Mode 0 Configurations
There are 16 configuration (16 control words) for mode 0 as shown below:
[78]
[79]
[80]
[81]
[82]
[83]
[84]
[85]
8. Problems
8.1.Problem 1:
Identify the mode 0 control word to configure port A and upper C as output port and port B and
lower c as input port.
Answer:
8.2.Problem2:
Write a control word to configure port A as input port in mode 0 and port B in mode 1 as output
port.
Answer: (same procedure as problem 1)
The control word is 10010100=94H
8.3.Problem 3:
A control word is given CW=CDH. Explain the conditions of ports of 8255A.
Answer:
CW = CDH = 11001101
D7=1; I/O Mode.
D6=1 and D5=0; Port A is in Mode 2.
D4=0; Port A is output port
[86]
8.4.Problem 4:
Figure bellow shows an 8255A interfaced with 8086 microprocessor. Perform the following:
a. Identify the Port Address.
b. Identify the Mode 0 control word to configure Port A and Port C (upper) as output ports
and Port B and Port C (lower) as input ports.
c. Write a program to read the Dual In-line Package (DIP) switches and display the reading
from Port B at Port A, and from Port CL at Port CU.
Answer:
a. This is a memory mapped I/O. when is high then the chip select is enabled
to Port Address
[87]
1 0 0 0 8000H : Port A
1 0 0 1 8001H : Port B
1 0 1 0 8002H : Port C
1 0 1 1 8003H : Control Register
: I/O = 1
= 0 (Port A = output )
= 0 (Port B in mode 0)
= 1 (Port B = input)
c. CODE
CONTROLREG EQU 8003H;
PORTC EQU 8002H;
PORTB EQU 8001H;
PORTA EQU 8000H;
MOV AL, 83H;
OUT CONTROLREG, AL;
IN AL, PORTB;
OUT PORTA, AL;
IN AL, PORTC;
AND AL, OFH;
MOV CL, 04;
ROL AL, CL;
OUT PORTC, AL;
HLT;
[88]
8.5.Problem 5
An 8086-8255 based microcomputer is required to drive an LED connected to bit 2 of Port B based
on two switch inputs connected to bit 6 and 7 of port A. If both switches are either high or low,
LED will turn on; otherwise, it will remain OFF. Assume base address of 60H. Write an 8086
assembly language program to accomplish this.
Answer:
PORTA EQU 60H
PORTB EQU 61H
CNTRL EQU 63H
MOV AL, 10010000B; Configure Port A as input and Port B as output.
OUT CNTRL, AL;
MAIN : IN AL, PORTA;
AND AL, 11000000B;
JPE LEADON; (JPE= Jump if parity even, p=1)
MOV AL, 00H;
OUT PORTB, AL;
JMP MAIN;
LEDON : MOV AL, 00000100B;
OUT PORTB, AL;
JMP MAIN;
8.6.Problem6
Write a BSR control word subroutine to set bit PC7 and PC3 and reset them after 10ms. Use
Figure of problem 4. Also write the delay procedure considering the processor clock at 5MHz.
Answer:
BSR control word
to Port Address
0 1 1 1 1 To set PC7: 00001111=0FH
0 1 1 1 0 To reset PC7: 00001110=0EH
[89]
[90]