You are on page 1of 116

GYANMANJARI INSTITUTE OF TECHNOLOGY

Bachelor of Engineering | Semester : 6 | Computer Engineering

Microprocessor and
Interfacing
Course Code : 3160712

Prof. Mayank K. Champaneri


Computer Engineering Department
SYLLABUS

UNIT TITLE % WEIGHTAGE


1 Introduction to Microprocessor 8%

2 Microprocessor Architecture and Operations 7%

3 8085 Microprocessor 12%

4 Assembly Language Basics 13%

5 8085 Assembly Language Programs 12%

6 Stack and Subroutines 13%

7 I/O Interfacing 20%

8 Advanced Microprocessor 15%


UNIT : 4

Assembly Language Basics


Looping 4
 Topics to be covered
 Assembly Language Programming Basics
 Hierarchy of Languages
 Compilers and Assemblers
 Instructions and Machine Language
 Advantages of High-Level Languages
 Why to Learn Assembly Language?

 Assembly Language Programming Tools


 Classification of 8085 Instructions
 Based on Byte Size
 Based on Function
5

Topic : 1

Assembly Language Programming Basics


Hierarchy of Languages
6
Application Program
• Assembly language is a
low-level programming
Machine Independent
High Level Language High Level Language language designed for a
specific type of
Machine Specific Low Level Language processor.
Assembly Language
• Uses symbolic names to
MOV represent operations,
BL,05h Machine Language registers and memory
ADD CL locations.
MUL BH
Micro Program
• Native to a
Control
processor:
1100 1011 executed directly
1100 1110
Hardware by hardware
0100 1111 • Instructions
consist of binary
code: 1s and 0s
Compilers and Assemblers
7
High Level Language

Compiler
Assemblers translates
assembly code to
Compiler Assembly Language machine code

Assembler

Machine Language

Compilers translate high-level programs to machine code


either directly, or Indirectly via an assembler
Instructions and Machine Language
8

 Each command of a program is called an instruction


(it instructs the computer, what to do?).

 Computers only deal with binary data, hence the instructions must be
in binary format (0’s and 1’s).

 Therefore, each Opcode is having unique bit pattern of (0’s and 1’s).
Instruction Fields
9

 Assembly language instructions usually are made up of several fields.


 Each field specifies different information.

The major two fields are:


1. Opcode:
Operation code that specifies operation to be performed.
Each operation has its unique opcode.

2. Operands:
Fields which specify, where to get the source and destination operands for the
operation specified by the opcode.
Instruction Fields
10

Opcode Operand
Rd, Rs
MOV M, Rs
R, M

Rd  Destination Register
Rs  Source Register
M  Memory
Translating Languages
11

English: Sum of A and B

High-Level Language: A + B

A statement in a high-level language is translated


typically into several machine-level instructions

Assembly Language: Machine Language:


MVI A,02 1001 1011 0010
MVI B,03 1001 1001 0011
ADD B
1011 0011 0010
Advantages of High-Level Languages
12

 Program development is faster


 High-level statements: fewer instructions to code.

 Program maintenance is easier


 As Higher Level Language contains fewer instruction code.

 Programs are portable


 Contain few machine-dependent details.
 Can be used with little or no modifications on different machines.
 Compiler translates to the target machine language.
Why to Learn Assembly Language?
13
 Accessibility to system hardware
 Assembly Language is useful for implementing system software.
 It is also useful for small embedded system applications.
 Space and Time efficiency
 Understanding sources of program efficiency.
 Tuning program performance.
 Writing compact code.
 It is helpful for
 Compiler writing
 Programming microcontrollers
 Device drivers
 System design
 Low-level numeric routines
14

Topic : 2

Assembly Language Programming Tools


Assembly Language Programming Tools
15

1. Assembler

2. Linker

3. Debugger

4. Editor
Assembly Language Programming Tools
16

Assembler
 An assembler is a program that converts programs written in assembly
language into object files(machine language).
 Popular assemblers have emerged over the years for the Intel family of
processors. These include …
 TASM (Turbo Assembler from Borland).
 NASM (Net wide Assembler for both Windows and Linux), and
 GNU assembler distributed by the free software foundation.
Assembly Language Programming Tools
17

Linker
 A linker program is required to produce executable files.

 It combines program's object file created by the assembler with other


object files and link libraries, to produces a single executable program.
Assembly Language Programming Tools
18
Assemble and Link Process
Source Object
File Assembler File

Source Object Executable


File Assembler File Linker
File

Link
Source Object
Assembler Libraries
File File

A project may consist of multiple source files


Assembler translates each source file separately into an object file
Linker links all object files together with link libraries
Assembly Language Programming Tools
19

Debugger

 Allows you to trace the execution of a program.

 Allows you to view code, memory, registers etc.

 Example: WinDbg, GDB - the GNU debugger, etc.


Assembly Language Programming Tools
20

Editor
 Allows to create assembly language source files.
 Some editors provide syntax highlighting features and can be customized as
per programming environment.
21

Topic : 3

Classification of 8085 Instructions


Classification of 8085 Instructions
22

Based on Byte Size Based on Function


One-byte Instructions Data Transfer Instructions
Requires one memory location
to perform an operation
Arithmetic Instructions
E.g. CMA, ADD

Two-byte Instructions Logic & Bit Manipulation


Requires two memory locations Instructions
to perform an operation Branch Instructions
E.g. MVI A,32H

Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
8085 Instructions
23
Instruction Set
 It is the set of instructions that the microprocessor can understand.
Opcode
 Known as Operation Code.
 This required field contains the mnemonic operation code for the 8085 instruction.
Operand
 The operand field identifies the data to be operated on by the specified opcode.
 Some instructions require no operands, while others require one or two operands.

MVI D, 8BH
Opcode Operand
8085 Instructions
24

General Terms
One-byte Instructions
25
One-byte Instructions
26
Sr. Instruction Sr. Instruction Sr. Instruction Sr. Instruction
1 MOV dest.,src 13 SBB R/M 25 RNZ 37 CMA
2 LDAX RP 14 INR R/M 26 RPE 38 CMC
(B/D)
3 STAX RP 15 INX RP 27 RPO 39 STC
4 XCHG 16 DCR R/M 28 RST 0-7 40 NOP
5 SPHL 17 DCX RP 29 CMP R/M 41 HLT
6 XTHL 18 DAA 30 ANA R/M 42 DI
7 PUSH RP 19 RET 31 XRA R/M 43 EI
8 POP RP 20 RC 32 ORA R/M 44 RIM
9 ADD R/M 21 RNC 33 RLC 45 SIM
10 ADC R/M 22 RP 34 RRC
11 DAD 23 RM 35 RAL
12 SUB R/M 24 RZ 36 RAR
Two-byte Instructions
27

In two-byte instruction,
1st Byte : Specifies Opcode
2nd Byte: Specifies Operand

Instruction
Binary Code Hexa Code
Opcode Operand
0011 1110 3E: 1st Byte
MVI A,32H
0011 0010 32: 2nd Byte
0011 1110 3E: 1st Byte
MVI B,F2H
1111 0010 F2: 2nd Byte
1101 1011 DB: 1st Byte
IN 0AH
0000 1010 0A: 2nd Byte
Two-byte Instructions
28
Three-byte Instructions
29

In three-byte instruction,
1st Byte: Specifies Opcode
2nd Byte: Specifies lower order 8-bit address
3rd Byte: Specifies higher order 8-bit address

Instruction
Binary Code Hexa Code
Opcode Operand
LDA 2050H 0011 1010 3A: 1st Byte
0101 0000 50: 2nd Byte
0010 0000 20: 3rd Byte
JMP 2085H 1100 0011 C3: 1st Byte
1000 0101 85: 2nd Byte
0010 0000 20: 3rd Byte
Three-byte Instructions
30
Classification of 8085 Instructions
31
Based on Byte Size Based on Function
One-byte Instructions Data Transfer Instructions
Requires one memory location
to perform an operation
Arithmetic Instructions
E.g. CMA, ADD

Two-byte Instructions Logic & Bit Manipulation


Requires two memory locations Instructions
to perform an operation Branch Instructions
E.g. MVI A,32H

Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
32

Group-1

Data Transfer Instructions


Classification of 8085 Instructions
33
Based on Byte Size Based on Function
One-byte Instructions Data Transfer Instructions
Requires one memory location
to perform an operation
Arithmetic Instructions
E.g. CMA, ADD

Two-byte Instructions Logic & Bit Manipulation


Requires two memory locations Instructions
to perform an operation Branch Instructions
E.g. MVI A,32H

Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Data Transfer Instructions
34

 Instructions copy data from source to destination.

 While copying, the contents of source is not modified.

 Data Transfer Instructions do not affect the flags.


Data Transfer Instructions
35
MOV: Move data from source to destination
36
MVI: Load 8-bit to Register/Memory
37
LDA: Load Accumulator
38
LDAX: Load the accumulator indirect
39
Example : LDAX
40
LXI: Load the immediate register pair
41
STA: Store Accumulator
42
STAX: Store Accumulator Indirect
43
LHLD: Load H and L registers direct
44
SHLD: Store H and L registers direct
45
XCHG: Exchange H and L with D and E
46
SPHL: Copy H and L registers to stack pointer
47
XTHL: Exchange H and L with top of stack
48
PUSH: Push the register pair onto the stack
49
POP: Pop off stack to the register pair
50
OUT: Output from Accumulator to 8-bit port
51
IN: Input data to accumulator from with 8-bit port
52
53

Group-2

Arithmetic Instructions
Classification of 8085 Instructions
54
Based on Byte Size Based on Function
One-byte Instructions Data Transfer Instructions
Requires one memory location
to perform an operation
Arithmetic Instructions
E.g. CMA, ADD

Two-byte Instructions Logic & Bit Manipulation


Requires two memory locations Instructions
to perform an operation Branch Instructions
E.g. MVI A,32H

Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Arithmetic Instructions
55
ADD: Add register/memory to accumulator
56
ADC: Add register to accumulator with carry
57
ADI: Add immediate 8-bit with accumulator
58
ACI: Add immediate 8-bit to accumulator with carry
59
DAD: Add register pair to H and L registers
60
Example : DAD Instruction
61
SUB: Subtract register/memory from accumulator
62
SBB: Subtract source & borrow from accumulator
63
SUI: Subtract immediate 8-bit from accumulator
64
SBI: Subtract immediate from accumulator with borrow
65
INR: Increment register/memory by 1
66
INX: Increment register pair by 1
67
DCR: Decrement register/ memory by 1
68
DCX: Decrement register pair by 1
69
DAA: Decimal Adjust Accumulator
70
Example : DAA Instruction
71
72

Group-3

Logical & Bit Manipulation


Instructions
Classification of 8085 Instructions
73
Based on Byte Size Based on Function
One-byte Instructions Data Transfer Instructions
Requires one memory location
to perform an operation
Arithmetic Instructions
E.g. CMA, ADD

Two-byte Instructions Logic & Bit Manipulation


Requires two memory locations Instructions
to perform an operation Branch Instructions
E.g. MVI A,32H

Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Logic & Bit Manipulation Instructions
74
CMP: Compare register/memory with accumulator
75
CPI: Compare immediate with accumulator
76
ANA: AND register/memory with accumulator
77
ANI: AND immediate with accumulator
78
ORA: OR register/memory with accumulator
79
ORI: OR immediate with accumulator
80
XRA: Exclusive OR register/memory with accumulator
81
XRI: Exclusive OR immediate with accumulator
82
RLC: Rotate accumulator left
83
Example : RLC
84
RRC: Rotate accumulator right
85
Example : RRC
86
RAL: Rotate accumulator left through carry
87
Example : RAL
88
RAR: Rotate accumulator right through carry
89
Example : RAR
90
CMA: Complement accumulator
91
CMC: Complement Carry
92
STC: Set Carry
93
94

Group-4

Branch Instructions
Classification of 8085 Instructions
95
Based on Byte Size Based on Function
One-byte Instructions Data Transfer Instructions
Requires one memory location
to perform an operation
Arithmetic Instructions
E.g. CMA, ADD

Two-byte Instructions Logic & Bit Manipulation


Requires two memory locations Instructions
to perform an operation Branch Instructions
E.g. MVI A,32H

Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Branch Instructions
96
JMP: Jump unconditionally
97
JMP: Jump unconditionally
98
JMP: Jump conditionally
99
RET: Return from subroutine unconditionally
100
CALL: Call Unconditionally
101
CALL: Call Unconditionally
102
CALL: Call conditionally
103
Return from Subroutine
104
PCHL: Load program counter with HL contents
105
RST: Restart
106
Branch Instruction
107

The 8085 has additionally 4 interrupts, which can generate RST


instructions internally and doesn’t require any external hardware.
108

Group-5

Control Instructions
Classification of 8085 Instructions
109
Based on Byte Size Based on Function
One-byte Instructions Data Transfer Instructions
Requires one memory location
to perform an operation
Arithmetic Instructions
E.g. CMA, ADD

Two-byte Instructions Logic & Bit Manipulation


Requires two memory locations Instructions
to perform an operation Branch Instructions
E.g. MVI A,32H

Control Instructions
Three-byte Instructions
Requires three memory locations
to perform an operation
E.g. JMP, CALL
Control Instructions
110
Control Instructions
111
Control Instructions
112
SIM: Set Interrupt Mask
113
SIM: Set Interrupt Mask
114
RIM: Read Interrupt Mask
115
THANK YOU

You might also like