De&mp Unit - 5
De&mp Unit - 5
COURSE MATERIAL
UNIT 5
COURSE B.TECH
DEPARTMENT CSE
SEMESTER 2-1
PREPARED BY Ms.C.Padma
(Faculty Name/s) Assistant Professor
Version V-1
BTECH_CSE-SEM 21
SVCE TIRUPATI
BTECH_CSE-SEM 21
SVCE TIRUPATI
BTECH_CSE-SEM 21
SVCE TIRUPATI
1. Course Objectives
The objectives of this course is to
1. Understand basics of 8086 Microprocessor.
2. Understand architecture of 8086 Microprocessor
3. Learn various 8086 instruction set and assembler directives.
4. To learn Assembly Language Programming of 8086
2. Prerequisites
Students should have knowledge on
1. Switching Theory and Logic Design
2. Computer Organization
3. Syllabus
4. Course outcomes
The outcome of this course is to
Design and develop any application using 8086 Microprocessor.
CO1 3 3 2 2 3 3
CO2 3 3 2 2 2 3
CO3 3 3 2 2 2 3
CO4 3 3 2 2 3 3
BTECH_CSE-SEM 21
SVCE TIRUPATI
2. Lesson Plan
Lecture No. Weeks Topics to be covered References
1 1 Introduction and Architecture of 8085 and 8086 T1, T2
microprocessor
2 Register organization and Flag register T1, T2
3 2 Pin diagram of 8086 microprocessor T1, T2
4 Timing & control signals of 8086 microprocessor T1, T2
5 3 Memory segmentation, organization & memory bank T1, T2
accessing
6 Interrupt structure of 8086 and interrupt vector table T1, T2
4. Lecture Notes
5.1 INTRODUCTION:
The INTEL 8086 is the first 16-bit processor released by INTEL in the year 1978. 8086 is
packed in a 40 pin DIP and requires a 5 Volt supply. 8086 microprocessor has a much
more powerful instruction set along with the architectural developments which imparted
substantial programming flexibility and improvement in speed over the 8-bit
microprocessors.
The 8086 does not have internal clock circuit. The 8086 requires an external
asymmetric clock source with 33% duty cycle. The 8284 clock generator is used to generate
the required clock for 8086. The maximum internal clock of 8086 is 5 MHz. The other
versions of 8086 with different
.clock rates are 8086-1, 8086-2 and 8086-4 with maximum internal clock frequency of
10MHz, 8MHz and 4MHz respectively.
Features of 8086
• It is a 16-bit microprocessor.
• 8086 has a 20 bit address bus can access up to 2^20 memory locations (1MB).
• It can support up to 64K I/O ports.
• It provides 14, 16 -bit registers.
• It has multiplexed address and data bus AD0- AD15 and A16 – A19.
• It requires single phase clock with 33% duty cycle to provide internaltiming.
• 8086 is designed to operate in two modes, Minimum andMaximum.
• It can pre-fetches up to 6 instruction bytes from memory and queuesthem in order
to speed up instruction execution.
• It requires +5V power supply.
SVCE TIRUPATI
• IN − Used to read a byte or word from the provided port to the accumulator.
• OUT − Used to send out a byte or word from the accumulator to the provided port.
Instructions to transfer the address
• LEA − Used to load the address of operand into the provided register.
• LDS − Used to load DS register and other provided register from the memory
• LES − Used to load ES register and other provided register from the memory.
Instructions to transfer flag registers
• LAHF − Used to load AH with the low byte of the flag register.
• SAHF − Used to store AH register to low byte of the flag register.
• PUSHF − Used to copy the flag register at the top of the stack.
• POPF − Used to copy a word at the top of the stack to the flag register.
memory location.
• OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided memory
location to the I/O port.
• SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in AL or string
word with a word in AX.
• LODS/LODSB/LODSW − Used to store the string byte into AL or string word into AX.
5.2.5 Program Execution Transfer Instructions (Branch and Loop Instructions)
• These instructions are used to transfer/branch the instructions during an execution. It
includes the following instructions −
• Instructions to transfer the instruction during an execution without any condition −
• CALL − Used to call a procedure and save their return address to the stack.
• RET − Used to return from the procedure to the main program.
• JMP − Used to jump to the provided address to proceed to the next instruction. Instructions
to transfer the instruction during an execution with some conditions −
• JA/JNBE − Used to jump if above/not below/equal instruction satisfies.
• JAE/JNB − Used to jump if above/not below instruction satisfies.
• JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
• JC − Used to jump if carry flag CF = 1
• JE/JZ − Used to jump if equal/zero flag ZF = 1
• JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.
• JGE/JNL − Used to jump if greater than/equal/not less than instruction satisfies.
• JL/JNGE − Used to jump if less than/not greater than/equal instruction satisfies.
• JLE/JNG − Used to jump if less than/equal/if not greater than instruction satisfies.
• JNC − Used to jump if no carry flag (CF = 0)
• JNE/JNZ − Used to jump if not equal/zero flag ZF = 0
• JNO − Used to jump if no overflow flag OF = 0
• JNP/JPO − Used to jump if not parity/parity odd PF = 0
• JNS − Used to jump if not sign SF = 0
• JO − Used to jump if overflow flag OF = 1
• JP/JPE − Used to jump if parity/parity even PF = 1
• JS − Used to jump if sign flag SF = 1
5.2.6 Processor Control Instructions
• These instructions are used to control the processor action by setting/resetting the flag
values. Following are the instructions under this group −
• STC − Used to set carry flag CF to 1
• CLC − Used to clear/reset carry flag CF to 0
• CMC − Used to put complement at the state of carry flag CF.
• STD − Used to set the direction flag DF to 1
• CLD − Used to clear/reset the direction flag DF to 0
• STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
• CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.
SVCE TIRUPATI
• Used to tell the assembler to declare the variable which is 10 bytes in length or reserve 10
bytes of storage in memory.
DW – Define Word
• Used to tell the assembler to define a variable type as word or reserve word in memory.
DUP: used to initialize several locations and to assign values to location
END – End the Program
• To tell the assembler to stop fetching the instruction and end the program execution.
ENDP – it is used to end the procedure.
ENDS – used to end the segment.
EQU – EQUATE
• Used to give name to some value or symbol.
EVEN – Align On Even Memory Address
• Tells the assembler to increment the location counter to the next even address if it is not
already at an even address.
EXTRN
• Used to tell the assembler that the name or labels following the directive are in some other
assembly module.
GLOBAL – Declares Symbols As Public Or Extrn
• Used to make the symbol available to other modules.It can be used in place of EXTRN or
PUBLIC keyword.
GROUP – Group related segment
• Used to tell the assembler to group the logical segments named after the directive into one
logical segment. This allows the content of all the segments to be accessed from the same
group.
INCLUDE – include source code from file
• Used to tell the assembler to insert a block of source code from the named file into the
current source module. This shortens the source code.
LABEL
• Used to give the name to the current value in the location counter. The LABEL directive must
be followed by a term which specifies the type you want associated with that name.
LENGTH
• Used to determine the number of items in some data such as string or array.
NAME
• Used to give a specific name to a module when the programs consisting of several modules.
OFFSET
• It is an operator which tells the assembler to determine the offset or displacement of named
data item or procedure from the start of the segment which contains it.
ORG – Originate
• Tells the assembler to set the location counter value.
• Example, ORG 7000H sets the location counter value to point to 7000H location in memory.
• $ is often used to symbolically represent the value of the location counter. It is used with ORG
to tell the assembler to change the location according to the current value in the location
counter. E.g. ORG $+100.
SVCE TIRUPATI
Assembly language is a common intermediate level programming language which is used for
microprocessor programming. This macro and procedure are two concepts in assembly by which
modular programming is implemented. So now let’s understand how macro and procedure are
different from each other.
Macro :
Macro is a set of instruction and the programmer can use it anywhere in the program by using its
name. It is mainly used to achieve modular programming. So same set of instructions can be used
multiple times when ever required by the help of macro.
Wherever macro’s identifier is used, it is replaced by the actual defined instructions during
compilation thereby no calling and return occurs.
Syntax of macro :
%macro macro_name number_of_parameters
<macro body>
%endmacro
Procedure:
Procedures are also like macro, but they are used for large set of instruction when macro is useful
for small set of instructions. It contains a set of instructions which performs a specific task. It
contains three main parts i.e Procedure name to identify the procedure, procedure body which
contains set of instructions, and RET statement which denotes return statement. Unlike macros,
procedures follow call-return method thereby achieving true modularity.
Syntax of Procedure:
Procedure_name
procedure body
…....................... RET
To call a procedure
CALL procedure_name
After execution of procedure control passes to the calling procedure using RET
statement.
SVCE TIRUPATI
Here machine code is created multiple Here machine code is created only once,
07. times as each time machine code is it is generated only once when the
generated when macro is called. procedure is defined.
08. In a macro parameter is passed as part In a procedure parameters are passed in
of statement that calls macro. registers and memory locations of stack.
09. Overhead time does not take place as Overhead time takes place during calling
procedure and returning control to calling
there is no calling and returning.
program.
➢ Each I/O port allotted a latch and a driver Latches allotted address in SFR. User can
communicate via these ports P0, P1, P2, and P3.
Serial Data Buffer:
➢ Internally had TWO independent registers, TRANSMIT buffer (parallel in serial
➢ out – PISO) and RECEIVE buffer (serial in parallel out –SIPO) identified by SBUF and
allotted an address in SFR.
Program Status Word (PSW):
➢ Set of flags contains status information as detailed below in the Figure 4.1.3.
ALU: Performs 8 bit arithmetic and logical operations over the operands held by TEMP1
and TEMP 2.
User cannot access temporary registers. SFR Register Bank: set of special
function registers address range: 80 H to FF H. Interrupt, serial port and timer units
control and perform specific functions under the control of timing and control unit.
An Addressing Mode is a way to locate a target Data, which is also called as Operand. The
8051 Family of Microcontrollers allows five types of Addressing Modes for addressing the
Operands. They are
• Immediate Addressing
• Register Addressing
• Direct Addressing
• Register – Indirect Addressing
• Indexed Addressing
Immediate Addressing
In Immediate Addressing mode, the operand, which follows the Opcode, is a constant
data of either 8 or 16 bits. The name Immediate Addressing came from the fact that the
constant data to be stored in the memory immediately follows the Opcode.
The constant value to be stored is specified in the instruction itself rather than taking from
a register. The destination register to which the constant data must be copied should be
the same size as the operand mentioned in the instruction.
Example: MOV A, #030H
Here, the Accumulator is loaded with 30 (hexadecimal). The # in the operand indicates
that it is a data and not the address of a Register.
Immediate Addressing is very fast as the data to be loaded is given in the instruction
itself.
Register Addressing
In the 8051 Microcontroller Memory Organization Tutorial, we have seen the organization
of RAM and four banks of Working Registers with eight Registers in each bank.
In Register Addressing mode, one of the eight registers (R0 – R7) is specified as Operand
in the Instruction.
SVCE TIRUPATI
It is important to select the appropriate Bank with the help of PSW Register. Let us see a
example of Register Addressing assuming that Bank0 is selected.
Example: MOV A, R5
Here, the 8-bit content of the Register R5 of Bank0 is moved to the Accumulator.
Direct Addressing
In Direct Addressing Mode, the address of the data is specified as the Operand in the
instruction. Using Direct Addressing Mode, we can access any register or on-chip variable.
This includes general purpose RAM, SFRs, I/O Ports, Control registers.
Here, the address for the operand is the sum of contents of DPTR and Accumulator.
NOTE: Some authors and textbooks add few other Addressing Modes like Absolute
Addressing Mode, Relative Addressing Mode and Long Addressing Mode.
Before seeing the types of instructions, let us see the structure of the 8051
Microcontroller Instruction. An 8051 Instruction consists of an Opcode (short of
Operation – Code) followed by Operand(s) of size Zero Byte, One Byte or Two
Bytes.
The Op-Code part of the instruction contains the Mnemonic, which specifies
the type of operation to be performed. All Mnemonics or the Opcode part of
the instruction are of One Byte size.
Coming to the Operand part of the instruction, it defines the data being
processed by the instructions. The operand can be any of the following:
• No Operand
• Data value
• I/O Port
• Memory Location
• CPU register
There can multiple operands and the format of instruction is as follows:
Based on the operation they perform, all the instructions in the 8051
Microcontroller Instruction Set are divided into five groups. They are:
BTECH_CSE-SEM 21
SVCE TIRUPATI
The Data Transfer Instructions are associated with transfer of data between
registers or external program memory or external data memory. The
Mnemonics associated with Data Transfer are given below.
• MOV
• MOVC
• MOVX
• PUSH
• POP
• XCH
• XCHD
Mnemonic Description
Arithmetic Instructions
BTECH_CSE-SEM 21
SVCE TIRUPATI
Logical Instructions
• The next group of instructions are the Logical Instructions, which perform
logical operations like AND, OR, XOR, NOT, Rotate, Clear and Swap.
Logical Instruction are performed on Bytes of data on a bit-by-bit basis.
BTECH_CSE-SEM 21
SVCE TIRUPATI
• ANL
• ORL
• XRL
• CLR
• RLC
• RR
• RRC
• SWAP
• CPL
• RL
• Boolean or Bit Manipulation Instructions
• As the name suggests, Boolean or Bit Manipulation Instructions deal with bit
variables. We know that there is a special bit-addressable area in the RAM
BTECH_CSE-SEM 21
SVCE TIRUPATI
and some of the Special Function Registers (SFRs) are also bit
addressable.
• CLR
• SETB
• MOV
• JC
• JNC
• JB
• JNB
• JBC
• ANL
• ORL
• CPL
Mnemonic Description
ORL Bitwise OR
BTECH_CSE-SEM 21
SVCE TIRUPATI
• nemonic • Description
• LJMP • Long Jump (Unconditional)
• AJMP • Absolute Jump (Unconditional)
• SJMP • Short Jump (Unconditional)
• JZ • Jump if A is equal to 0
• JNZ • Jump if A is not equal to 0
• CJNE • Compare and Jump if Not Equal
• DJNZ • Decrement and Jump if Not Zero
• NOP • No Operation
• LCALL • Long Call to Subroutine
• ACALL • Absolute Call to Subroutine (Unconditional)
• RET • Return from Subroutine
• RETI • Return from Interrupt
• JMP • Jump to an Address (Unconditional)
BTECH_CSE-SEM 21
SVCE TIRUPATI
9. PRACTICE QUIZ
1. 8086 microprocessor could address of memory
a) 1MB
b) 2MB
c) 64KB
d) 64MB
BTECH_CSE-SEM 21
SVCE TIRUPATI
BTECH_CSE-SEM 21
SVCE TIRUPATI
10. ASSIGNMENTS
S.No Question BL CO
1
1
2
What is stack pointer (sp)?
Ans. Stack pointer (SP) is a 8 bit wide register and is incremented
before the data is stored into the stack using PUSH or CALL 1
2
instructions.
It contains 8-bit stack top address. It is defined anywhere in the
on-chip 128-byte RAM. After reset, the SP register is initialized to 07.
After each write to stack operation, the 8-bit contents of the
operand are stored onto the stack, after incrementing the SP
register by one.
It is not a top-down data structure. It is allotted an address in the
special function register bank.
3
What is the purpose of using instruction register?
Ans. Instruction register is used for the purpose of decoding
the opcode of an instruction to be executed and gives 1
1
information to the timing and control unit generating necessary
signals for the execution of the instruction.
BTECH_CSE-SEM 21
SVCE TIRUPATI
6
2. What is indexed addressing?
Ans.
BTECH_CSE-SEM 21
SVCE TIRUPATI
a. CJNE
b. CLR
10 What Is SFR?
Ans. In the 8051 microcontroller registers A, B, PSW and DPTR
are part of the group of registers commonly referred to as
special function registers (SFR).
BTECH_CSE-SEM 21
SVCE TIRUPATI
1 8051
• Microcontrollers are used in automatically controlled products and devices, such
asLight sensing and controlling devices.
• Temperature sensing and controlling devices. 1
• Fire detections and safety devices.
• Automobile applications.
• Defense applications.
BTECH_CSE-SEM 21
SVCE TIRUPATI
Reference Books:
1. Thomas L. Floyd, Digital Fundamentals – A Systems Approach, Pearson, 2013.
2. Charles H. Roth, Fundamentals of Logic Design, Cengage Learning, 5th, Edition,
2004.
3. D.V.Hall, Microprocessors and Interfacing. TMGH, 2nd edition, 2006.
4. Kenneth.J.Ayala, The 8051 microcontroller, 3rd edition, Cengage Learning,2010.
BTECH_CSE-SEM 21