0% found this document useful (0 votes)
9 views34 pages

8085 Microprocessor Practical Guide

The document is a practical handbook for the Computer Science Paper II examination, focusing on the 8085 microprocessor. It outlines the practical examination scheme, including the distribution of marks and a detailed index of practical programming tasks. Additionally, it provides an overview of the 8085 microprocessor architecture, instruction set, and practical programming examples for students to follow.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views34 pages

8085 Microprocessor Practical Guide

The document is a practical handbook for the Computer Science Paper II examination, focusing on the 8085 microprocessor. It outlines the practical examination scheme, including the distribution of marks and a detailed index of practical programming tasks. Additionally, it provides an overview of the 8085 microprocessor architecture, instruction set, and practical programming examples for students to follow.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

COMPUTER SCIENCE

PAPER II

PRACTICAL HANDBOOK FOR S.Y.J.C


SCHEME OF PRACTICAL EXAMINATION

Time : 3hours Computer Science paper - II

Paper –I - 50 marks , Paper – II -50 marks


Paper – I includes C++ programming, Visual Basic 6.0 programming and HTML
Paper – II based upon 8085 processor
Every student should perform one practical in both Paper – I as well as Paper-II. Each practical
will be of 3 hours duration.

Distribution of marks : [For Paper – I & Paper – II]


i) Writing & executing Program 30 marks
ii) Journal & viva 20 marks
TOTAL 50 marks

C S I I P r a c t i c a l H a n d b o o k P a g e 1 | 34
INDEX - Computer Science [Paper – II]

Sr TITLE Page
No No
01. Introduction to microprocessor
02. 8085 microprocessor & instruction set
03. Addition of two 8-bit numbers.
04. Addition of two 8 bit BCD numbers.
05. Write a program to subtract two numbers.
06 Program to exchange the contents of two blocks stored in different
memory Locations.

07 Program to transfer data in a reverse order.


08 Program to find first occurrence of a data in a given block.
09 Program to find how many times data appears in a block.
10 Program to count zero in a given number.
11 Program to multiply two 1 byte hex numbers.
12 Write a Program that divides two 1 byte hex numbers.
13 Program to add the BCD contents of a block of memory.
14 Write a program that adds the contents of a block of memory using
DAD instruction
15 To accept a two hex numbers from keyboard using monitor subroutine.
16 To use Microprocessor kit as a calculator using monitor subroutine.

C S I I P r a c t i c a l H a n d b o o k P a g e 2 | 34
Microprocessor
Microprocessor is a multipurpose, programmable device that accepts digital data as input,
processes it according to instructions stored in its memory, and provides results as output.
Microprocessors use three steps commonly called Fetch, Decode, and Execute. In the Fetch step,
an instruction is copied from the memory of the computer into the microprocessor. In the Decode
step, the microprocessor figures out what operation the instruction is meant to do. In the
Execute step, this operation is performed.

Three basic characteristics differentiate microprocessors:


• Instruction set: The set of instructions that the microprocessor can execute.
• Bandwidth: The number of bits processed in a single instruction.
• Clock speed: Given in megahertz (MHz), the clock speed determines how many instructions
per second the processor can execute.
Assembly language
An assembly language is a low-level programming language for microprocessors,
microcontrollers, and other programmable devices in which each statement corresponds to a
single machine language instruction. Each microprocessor has its own set of instructions.
Instructions are in machine language (0 and 1) also known as binary digits (bits).It is very
difficult to write a program in machine language, so special codes/ symbolic code for each
instruction are developed which is known as mnemonics.

Mnemonics is a set of binary code/instruction that the CPU understands. Based on the CPU, the
instruction can be one byte, two bytes or longer.1byte=8 bits. The instruction code is
usually followed by one or two operands.

Mnemonics example: -
Instruction operand operand
Code 1 2
MOV A, B

The above instruction moves the value of register B to the specified register A. (register is a
special memory located inside the CPU, where data can be stored on which arithmetic operations
can be performed).

8085 microprocessor (µp)

The 8085 µp is an 8-bit microprocessor introduced by Intel in [Link] has 8-bit data bus and 16-
bit address bus. It is a 40-pin DIP chip designed using NMOS. It operates with a power supply of
+5 volts and GND. It operates at 3.2 MHZ single phase clock. 8085 generates the clock signal internally
by dividing the external supplied clock signal by two. It has 16-bit address bus and hence can
address up to 216 = 65536 bytes (64KB) memory locations.

C S I I P r a c t i c a l H a n d b o o k P a g e 3 | 34
Functional block diagram or architectures of 8085 µp.

8085 Bus Structure:

Address Bus:

 The address bus is a group of 16 lines generally identified as A0 to A15.


 The address bus is unidirectional, bits flow in one direction from the µp to peripheral
devices.

Data Bus:

 The data bus is a group of eight lines used for data flow.
 These lines are bi-directional, data flow in both directions between the µp and memory and
peripheral devices.
 The largest number that can appear on the data bus is 11111111.

Control Bus:

 The control bus carries synchronization signals and providing timing signals.
 The µp generates specific control signals for every operation it performs. These signals are
used to identify a device type with which the µp wants to communicate.

C S I I P r a c t i c a l H a n d b o o k P a g e 4 | 34
Registers of 8085

 The 8085 have six general-purpose registers to store 8-bit data during program execution.
 These registers are identified as B, C, D, E, H, and L.
 They can be combined as register pairs-BC, DE, and HL to perform some 16-bit operations.

Accumulator (A):

 The accumulator is an 8-bit register that is part of the arithmetic/logic unit (ALU).
 This register is used to store 8-bit data and to perform arithmetic and logical operations.
 The result of an operation is stored in the accumulator.

Temporary registers:-

 The temporary registers W and Z are intended for internal use of the processor and it
cannot be used by the programmer.

Stack Pointer (SP):

 The stack pointer (SP) holds the address of the stack top. The stack is a sequence of RAM
memory locations defined by the programmer. The stack is used to save the content
of registers during the execution of a program.

Program Counter (PC):

 The function of the program counter is to point to the memory address from which the
next byte is to be fetched. When a byte is being fetched, the program counter is
incremented by one to point to the next memory location.

Flags:

 The ALU includes five flip-flops that are set or reset according to the result of an operation.
 The microprocessor uses the flags for testing the data conditions.
 They are Zero (Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags. The most
commonly used flags are Sign, Zero, and Carry.

The bit position for the flags in flag register is,

1. Sign Flag (S):

C S I I P r a c t i c a l H a n d b o o k P a g e 5 | 34
After execution of any arithmetic and logical operation, if D7 of the result is 1, the sign flag
is set. Otherwise it is reset. If D7 is 1, the number will be viewed as negative number else it is
positive number.

2. Zero Flag (z):

If the result of arithmetic and logical operation is zero, then zero flag is set (1) otherwise it is
reset (0).

3. Auxiliary Carry Flag (AC):

If D3 generates any carry when doing any arithmetic and logical operation, this flag is set
(1). Otherwise it is reset (0).

4. Parity Flag (P):

If the result of arithmetic and logical operation contains even number of 1's then this flag
will be set (1) and if it is odd number of 1's it will be reset (0). 8085 uses ODD parity.

5. Carry Flag (CY):

If any arithmetic and logical operation generates any carry then carry flag is set (1)
otherwise it is reset (0).

8085 instruction set

 8085 Instruction is called a mnemonic.


 A mnemonic is made up of opcode and operand.
 Opcode is the code which is going to work
 Operand is data on which the code is going to work.
 Instructions are of a typical width, single byte, two byte or three byte instruction.
 Instruction width is defined as: Number of locations occupied in memory.
 Instructions are written in hex system.
 In the instruction address is written as: Lower byte; higher byte.

Types of Addressing Modes


 Intel 8085 uses the following addressing modes:
1. Direct Addressing Mode:-
In this mode, the address of the operand is given in the
instruction itself. Ex:-LDA
2. Register Addressing Mode:-
In this mode, the operand is in general purpose
register. Ex: MOV A, B
3. Register Indirect Addressing Mode :-
In this mode, the address of operand is specified by a
register pair. Ex: - MOV A, M
4. Immediate Addressing Mode :-
In this mode, the operand is specified within the
instruction itself. Ex: - MVI B, 10 H
5. Implicit Addressing Mode:-

C S I I P r a c t i c a l H a n d b o o k P a g e 6 | 34
If address of source of data as well as address of destination of result is fixed, then
there is no need to give any operand along with the instruction. Ex: - CMA

Microprocessor kit

General Instruction to execute the program in microprocessor Kit:-

(1)Type the program Hexcode from C000 till Opcode RST1.


(2)Press “Increment (INR)” button.
(3)Enter the required data in the specified memory location.(Ex. C030 & C031)
RESET SET  C030  Type data  INR  Type data for C031.
(4)Press “Increment (INR)” button.
(5)To execute program, first press “Reset (RES)” button then “Go” button & type
C000 & press “Execute (EXEC)” button.
(6)If FRIEND message comes on display, program is executed successfully.
(7)To check Register data :- Press “Register(REG)” button & press register A, note
the register data. Go on pressing “Increment (INR)” button & note all register
data.

C S I I P r a c t i c a l H a n d b o o k P a g e 7 | 34
(8)Go to specified memory location to verify the result. Ex: If result is in C032 &
C033 then
Follow following steps:
Reset  set  C032  INR (See result on display unit)  INR  C033 data
displayed

C S I I P r a c t i c a l H a n d b o o k P a g e 8 | 34
Board Practical Exam Questions with their solutions

Practical No: 1

Write a program to do addition between two 8 bit numbers. Two numbers are stored
in C030H & C031H. Store the result in C032H.

Program Steps:-

1. This Program is to do addition between two [Link] fetch the data from memory
location [Link] this initialize HL pointer to C030 location.
2. Wherever HL pointer points that memory location’s data can be fetched with use of
memory variable M. Transfer that data from memory variable M to register A.
3. Increment HL pointer, so it points to next memory location C031. Data of C031 can be
taken by memory variable M.
4. By using Arithmetic instruction do the addition between register A (First no) & Memory
variable M (Second no). Result of addition is stored in Accumulator (A).
5. Store the result from Accumulator to Memory location C032.
Flow of the program:-

START

Initialize HL to [Link] data of C030


to register A

Move Pointer HL to next memory i.e


C031

Add data of Accumulator (A) with M

Store Result from Accumulator to


memory location C032

STOP

C S I I P r a c t i c a l H a n d b o o k P a g e 9 | 34
Program:

Addres HexC Comment


Label Mnemonics
s ode
Opcod
Operand
e
;Initialize HL as a
C000 START LXI H ,C030 21
Memory Pointer
C001 30 ;Lower address byte
C002 C0 ;Upper address byte.
;Move the first
C003 MOV A,M 7E
number in A reg.
;Increment HL
C004 INX H 23
Pointer by one
;Add accumulator
C005 ADD M 86 data with HL Pointer
data
;Store result in
C006 STA C032 32
memory location
C007 32 ;Lower address byte
C008 C0 ;Upper address byte.
;Stop Program
C009 STOP RST1 CF
Execution
Details after program execution:

Before Execution After Execution


Memory Data Memory Location Data
Location
C030 06 C030 06
C031 07 C031 07
C032 00 C032 0D

GENERAL REGISTERS
(* indicates register not used in program .Data after execution for these register can be
changed)

A B* C* D* E* F H L
0D 00 00 00 7B 00 C0 31

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z X AC X P X CY
0 0 0 0 0 0 0 0

C S I I P r a c t i c a l H a n d b o o k P a g e 10 | 34
Questions: Explain LXI & STA instructions. Which flags are affected with instruction ADD.?

Practical No: 2

Write a program to do addition between two 8 bit BCD numbers. Two numbers are
stored in D030H & D031H. Store the result in D032H onwards starting with least
significant bit.
Program Steps:-
1. This Program is to do addition between two BCD (Binary coded decimal) numbers. First
fetch the data from memory location [Link] this initialize HL pointer to D030 location.
2. Assign a zero to a variable to store carry if generated, register C is used for this. Wherever
HL pointer points that memory location’s data can be fetched with use of memory variable
M. Transfer that data from memory variable M to register A.
3. Increment HL pointer, so it points to next memory location D031. Data of D031 can be
taken by memory variable M.
4. By using Arithmetic instruction do the addition between register A (First no) & Memory
variable M (Second no). Result of addition is stored in Accumulator (A).
5. Result in accumulator is in Hexadecimal. We want result in BCD, so do the conversion with
DAA (Decimal Adjust Accumulator) instruction.
6. After conversion if carry is generated register C value is incremented by [Link] it will
remain 0.
7. Store the result from Accumulator to Memory location D032.
8. Transfer data from register C to Accumulator & store the carry result in D033.

Program:

HexCod
Label Mnemonics Comment
Address e
Operan
Opcode
d
;Initialize HL as a Memory
C000 START LXI H ,D030 21
Pointer
C001 30 ;Lower address byte
C002 D0 Upper address byte.
C003 MVI C,00 H 0E Initialize C reg. with zero.
C004 00
Move the first number in A
C005 MOV A,M 7E
reg.
Increment HL Pointer by
C006 INX H 23
one.
Add accumulator data with
C007 ADD M 86
HL Pointer data
Decimal adjust
C008 DAA 27
accumulator
If carry not generated Jump
C009 JNC C00D D2
to C00D
C00A 0D Lower address byte

C S I I P r a c t i c a l H a n d b o o k P a g e 11 | 34
C00B C0 Upper address byte.
C00C INR C 0C Increment C reg. by one
Store result in memory
C00D L1 STA D032 H 32
location
C00E 32 Lower address byte
C00F D0 Upper address byte.
Move C reg. data to
C010 MOV A,C 79
accumulator
Store carry in memory
C011 STA D033 H 32
location
C012 33 Lower address byte
C013 D0 Upper address byte.
C014 RST 1 CF Stop Program Execution

Details after program execution:

Before Execution After Execution

Memory Data Memory Data


Location Location
D030 09 D030 09
D031 06 D031 06
D032 00 D032 15

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B* C D* E* F H L
00 01 00 00 00 10 D0 31

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 0 1 0 0

Questions:

1. Explain working of DAA instructions with example.


2. Explain STA instruction. Which other instruction can be used in place of STA instruction in
above program.

C S I I P r a c t i c a l H a n d b o o k P a g e 12 | 34
Practical No: 3

Write a program that subtracts the number stored in C030 H from the number stored
in C031 H. Store the absolute difference in memory location C032H as result.
Program:
Addres HexCod
Label Mnemonics Comment
s e
Operan
Opcode
d
Initialize HL as a memory
C000 LXI H ,C030 21
Pointer.
C001 30 Lower address byte
C002 C0 Upper address byte.
C003 MOV B,M 46 Move subtractor to B reg.
C004 INX H 23 Increment HL Pointer by 1
C005 MOV A,M 7E Move Minuend to A reg.
C006 SUB B 90 Subtract A minus B
If result is positive go to
C007 JP C00D H F2
Label VP
C008 0D Lower address byte
C009 C0 Upper address byte.
Take 1’s complement of A
C00A CMA 2F
reg
Add 1 to A reg to get 2’s
C00B ADI 01 H C6
complement
C00C 01
C00D VP INX H 23 Increment HL Pointer by 1
C00E MOV M,A 77 Move A contents to memory
C00F RST1 CF Stop Program Execution

Note: - As we want absolute result, we use CMA (complement) instruction to get 1’s
complement & then we add 1 to it so we will get 2’s complement.2’s complement of a negative
number gives you Positive number.
Before Execution After Execution
Memory Data Memory Data
Location Location
C030 06 C030 06
C031 0A C031 0A
C S I I P r a c t i c a l H a n d b o o k P a g e 13 | 34
C032 04
GENERAL REGISTERS (* indicates register not used in program .Data after execution for these
register can be changed)
A B C* D* E* F H L
01 06 00 00 00 00 C0 32
FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z X AC X P X CY
0 0 0 0 0 0 0 0

Practical No: 04

A block of data is stored in memory locations from C060 H to C06A [Link] block of
data having the same length is stored in memory locations starting from C100. Write
a program to exchange the contents of these two blocks.

Program:

Addres HexCod
Label Mnemonics Comment
s e
Opcode Operand
Move length of Block to c
C000 START MVI C,OB H 0E
reg. as counter.
C001 0B
Store starting Address of
C002 LXI H,C060 21
given data in HL
C003 60 Lower address byte
C004 C0 Upper address byte.
Store starting Address of
C005 LXI D,C100H 11 block in DE where data is to
be transferred.
C006 00 Lower address byte
C007 C1 Upper address byte.
Load Accumulator data in
C008 LOOP LDAX D 1A
memory pointed by DE pair
Copy data pointed by HL
C009 MOV B, M 46
pair to B reg.
Copy Accumulator data to
C00A MOV M, A 77
memory pointed by HL
Copy B reg. data to
C00B MOV A, B 78
Accumulator
Store Accumulator to
C00C STAX D 12
memory pointed by DE
C00D INX H 23 Increment HL by1.
C00E INX D 13 IncrementDE by 1
C00F DCR C 0D Decrement counter by 1
Jump to M.L C008, if C
C010 JNZ C008H C2
(counter) is not zero.
C S I I P r a c t i c a l H a n d b o o k P a g e 14 | 34
C011 08 Lower address byte
C012 C0 Upper address byte.
Stop the program
C013 STOP RST 1 CF
execution.

Details after program execution:

Before Execution After Execution

Memory Data Memory Data Memory Data Memory Data


Location Locatio Locatio Locatio
n n n
C060 01 C100 20 C060 20 C100 01
C061 02 C101 21 C061 21 C101 02
C062 03 C102 22 C062 22 C102 03
C063 04 C103 23 C063 23 C103 04
C064 05 C104 24 C064 24 C104 05
C065 06 C105 25 C065 25 C105 06
C066 07 C106 26 C066 26 C106 07
C067 08 C107 27 C067 27 C107 08
C068 09 C108 28 C068 28 C108 09
C069 10 C109 29 C069 29 C109 10
C06A 11 C10A 30 C06A 30 C10A 11

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B C D E F H L
11 11 00 C1 0B 54 C0 6B

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z X AC X P X CY
0 1 0 1 0 1 0 0

C S I I P r a c t i c a l H a n d b o o k P a g e 15 | 34
Questions:

1. Differentiate between LDAX & LDA.


2. Differentiate between STA & STAX.

Practical No: 05

A block of data is stored in memory locations from C080 H to C08B [Link] a program
to transfer the data in reverse order to memory location starting from C180 H.

Program:

Addres HexCod
Label Mnemonics Comment
s e
Opcode Operand
C000 START MVI C,OC H OE Store block length in c reg.
C001 OC
Initialize HL to last address
C002 LXI H,CO8B 21
of source data at C08B H
C003 8B Lower address byte
C004 C0 Upper address byte.
Initialize DE to starting
C005 LXI D,C180 H 11 address of destination
block C180 H
C006 80 Lower address byte
C007 C1 Upper address byte.
Move memory data to
C008 LOOP MOV A,M 7E
accumulator
Store accumulator data to
C009 STAX D 12
memory pointed by DE
C00A DCX H 2B Decrement HL by 1.
C00B INX D 13 IncrementDE by 1.
C00C DCR C 0D Decrement counter C by 1
Jump to C008 if C data is
C00D JNZ C008 C2
not zero
C00E O8 Lower address byte
C00F C0 Upper address byte.
C010 RST1 CF Stop Program.
Details after program execution:

C S I I P r a c t i c a l H a n d b o o k P a g e 16 | 34
Before Execution After Execution

Memory Location Data Memory Location Data


C080 00 C180 11
C081 01 C181 10
C082 02 C182 09
C083 03 C183 08
C084 04 C184 07
C085 05 C185 06
C086 06 C186 05
C087 07 C187 04
C088 08 C188 03
C089 09 C189 02
C08A 10 C18A 01
C08B 11 C18B 00

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B* C D E F H L
00 01 00 C1 8C 54 C0 7F

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0

C S I I P r a c t i c a l H a n d b o o k P a g e 17 | 34
Practical No: 06

Write a program to find first occurrence of AB H data. The length of the block is
stored at C07F [Link] data stored from memory location [Link] the address of
this occurrence in HL pair. If data is not found store FFFF H in HL pair.

Program:

Addres HexCod
Label Mnemonics Comment
s e
Operan
Opcode
d
C000 LXI H,C07FH 21 HL pointer points to C07F
C001 7F Lower address byte
C002 C0 Upper address byte.
C003 MOV C, M 4E Move memory data to C reg
Move searched data ABH to A
C004 MVI A,AB H 3E
reg.
C005 AB
C006 S1 : INX H 23 Increment HL by 1
Compare accumulator data &
C007 CMP M BE
memory
If zero flag is set jump to label
C008 JZ C012 H CA
stop
C009 12 Lower address byte
C00A C0 Upper address byte.
C00B DCR C 0D Decrement counter by 1
If C reg not zero then goto
C00C JNZ C006 C2
label S1.
C00D 06 Lower address byte
C00E C0 Upper address byte.
HL pair contents FFFF as data
C00F LXI H,FFFF 21
not available
C010 FF
C011 FF
C012 Stop: RST1 CF Stop the program
Details after program execution:
Before Execution After Execution
Memory Location Data Memory Location Data
C07F 05 C07F 05
C080 21 C080 21
C081 AB C081 AB
C082 33 C082 33
C083 AB C083 AB
C084 BC C084 BC
C S I I P r a c t i c a l H a n d b o o k P a g e 18 | 34
RESULT IS STORED IN “HL” REGISTER PAIR.

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B* C D* E* F H L
AB 01 04 00 00 54 C0 81

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0

C S I I P r a c t i c a l H a n d b o o k P a g e 19 | 34
Practical No: 07

Write a program to find how many times data AD H appears in memory block starting
from C030 H and length of block is at C02F H. Store the count in D000H .

Program:

Addres HexCod
Label Mnemonics Comment
s e
Operan
Opcode
d
C000 MVI C,00 0E Move 00 to C reg
C001 00 H
C002 MVI A,AD H 3E Move AD data to A reg
C003 AD H
H,C02F
C004 LXI 21 Initialize HL with C030
H
C005 2F Lower address byte
C006 C0 Upper address byte.
C007 MOV B,M 46 Move memory data to B reg
C008 INX H 23
Compare accumulator &
C009 BACK CMP M BE
memory data.
If zero flag is not set, goto
C00A JNZ C00E C2
label NEXT
C00B 0E Lower address byte
C00C C0 Upper address byte.
C00D INR C 0C Increment counter by 1
C00E NEXT INX H 23 Increment HL pair by 1
C00F DCR B 05 Decrement B reg
If zero flag not set, goto label
C010 JNZ C009 C2
BACK
C011 09 Lower address byte
C012 C0 Upper address byte.
C013 MOV A,C 79 Move memory data to A reg
Store accumulator data to
C014 STA D000 H 32
memory location 2000
C015 00 Lower address byte
C016 D0 Upper address byte.
C017 RST1 CF Stop the program

Details after program execution:


Before Execution After Execution
Memory Data Memory Data
Location Location
C02F 04 C02F 04
C030 12 C030 12

C S I I P r a c t i c a l H a n d b o o k P a g e 20 | 34
C031 AD C031 AD
C032 34 C032 34
C033 AD C033 AD
D000 02

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B C D* E* F H L
02 00 02 00 00 54 C0 34

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0

C S I I P r a c t i c a l H a n d b o o k P a g e 21 | 34
Practical No: 08

A 8-bit number is stored in memory location C400 H. Write an assembly language


program to count the zero in the given number. Store count in memory location C500
H.

Program:

Addres HexCod
Label Mnemonics Comment
s e
Operan
Opcode
d
C000 MVI C,08 H 0E Set counter to 08 H
C001 08 H
Set B to 00 to store number of
C002 MVI B,00 H 06
zeros
C003 00 H
C004 LDA C400 H 3A Get number in A
C005 00 Lower address byte
C006 C4 Upper address byte.
Shift Least significant bit in
C007 BACK RRC 0F
carry
C008 JC DA Is carry? Yes go to Next
C009 0C Lower address byte
C00A C0 Upper address byte.
C00B INR B 04 Increment B reg. by 1.
C00C NEXT DCR C 0D Decrement C by 1
C00D JNZ C2 Is counter =0? No go to Back
C00E 07 Lower address byte
C00F C0 Upper address byte.
Get contents of B reg. in A
C010 MOV A,B 78
reg.
C011 STA C500 H 32 Store result in C500 H
C012 00 Lower address byte
C013 C5 Upper address byte.
C014 RST1 CF Stop the program.
Details after program execution:
Before Execution After Execution
Memory Location Data Memory Location Data
C400 75 C400 75
C500 03

GENERAL REGISTERS

C S I I P r a c t i c a l H a n d b o o k P a g e 22 | 34
(* indicates register not used in program .Data after execution for these register can be
changed)

A B C D* E* F H* L*
03 03 00 00 00 54 FF FE
FLAG REGISTER
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0

Practical No: 09

Write a program that multiplies two 1-byte hex numbers stored in consecutive
memory locations starting from C030 Store the two-byte result in consecutive
memory locations starting from C032 beginning with lower order byte.

Program:

Addres HexCod
Label Mnemonics Comment
s e
Opcod Operan
e d
C000 START XRA A AF Clear the A reg. to zero
Initialize B reg. to zero to record
C001 MOV B, A 47
higher byte
Initialize HL reg. as memory
C002 LXI H ,C030 21
pointer
C003 30 Lower address byte
C004 C0 Upper address byte.
C005 MOV C, M 4E Move length in C reg.
C006 INX H 23 Increment HL Pointer by one.
Add memory content to
C007 L1 ADD M 86
Accumulator
C008 JNC C00C H D2 If cy=0 then jump to label P1
C009 OC Lower address byte
C00A C0 Upper address byte.
C00B INR B 04 Increment B reg. by one.
C00C P1 DCR C OD Decrement C reg. by one.
If counter c is not zero goto
C00D JNZ C007 C2
label L1
C00E 07 Lower address byte
C00F C0 Upper address byte.
C010 INX H 23 Increment HL Pointer by one

Move Result from Accumulator


C011 MOV M, A 77 to memory location pointed by
HL.
C012 INX H 23 Increment HL Pointer by one
C013 MOV M, B 70 Move carry from B reg. to
C S I I P r a c t i c a l H a n d b o o k P a g e 23 | 34
memory location pointed by HL
C014 STOP RST CF Stop Program Execution.
Note:- Multiplication is done as repeated addition.
Before Execution After Execution

Memory Data Memory Data


Location Location
C030 09 C030 09
C031 05 C031 05
C032 00 C032 2D
C033 00 C033 00

GENERAL REGISTERS
(* indicates register not used in program .Data after execution for these register can be
changed)
A B C D* E* F H L
2D 00 00 00 00 54 C0 33

FLAG REGISTER
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0

Questions:

1. Explain XRA instruction & write another instruction for same operation as XRA in above
program.

C S I I P r a c t i c a l H a n d b o o k P a g e 24 | 34
Practical No: 10

Write a program that divides two 1-byte hex numbers where the dividend is stored in
C030 H and the divisor stored in C031 H. Store the quotient and the reminder in the
next consecutive memory locations respectively.

Program:

Addres HexCod
Label Mnemonics Comment
s e
Operan
Opcode
d
C000 START XRA A AF Clear the A reg. to zero.
Initialize B reg. to zero to
C001 MOV B,A 47
record quotient.
Initialize HL as a memory
C002 LXI H ,C030 21
Pointer.
C003 30 Lower address byte
C004 C0 Upper address byte.
C005 MOV A, M 7E Move dividend in A reg.
Increment HL Contents by
C006 INX H 23
one.
Compare to check dividend is
C007 PP CMP M BE
greater than divisor
C008 JC C010 H DA If A<M then go to label VP
C009 10 Lower address byte
C00A C0 Upper address byte.
C00B SUB M 96 Subtract divisor from dividend
C00C INR B 04 Increment quotient by one.
Jump unconditionally to Label
C00D JMP C007 C3
PP
C00E 07 Lower address byte
C00F C0 Upper address byte.
Increment HL Contents by
C010 VP INX H 23
one.
C011 Store quotient at C032 H
MOV M,B 70

Increment HL Contents by
C012 INX H 23
one.
C013 MOV M,A 77 Store reminder at C033 H
C014 RST1 CF Stop the Execution.

Details after program execution:


Before Execution After Execution
Memory Data Memory Data
Location Location

C S I I P r a c t i c a l H a n d b o o k P a g e 25 | 34
C030 0D C030 0D
C031 03 C031 03
C032 04
C033 01

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B C* D* E* F H L
01 04 00 00 00 81 C0 33

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
1 0 0 0 1

Questions:

1. Explain working of CMP instruction.


2. Why JMP instruction is used in above program?

C S I I P r a c t i c a l H a n d b o o k P a g e 26 | 34
Practical No: 11

Write a program that adds the BCD contents of a block of memory. Block length in hex
not exceeding 63H=9910 is stored at C0FF and starting address of block is C100. Store
the BCD sum as result starting from memory location C060.

Program:

Addres Labe HexCod


Mnemonics Comment
s l e
Operan
Opcode
d
C000 XRA A AF Make A reg contents zero
C001 MOV B,A 47 Make B reg contents zero
HL pointer points to memory
C002 LXI H ,C0FF 21
location C0FF
C003 FF Lower address byte
C004 C0 Upper address byte.
C005 MOV C, M 4E Move memory contents to reg C
C006 S1 INX H 23 Increment HL by 1
Add memory contents with
C007 ADD M 86
accumulator
C008 DAA 27 Decimal Adjust Accumulator
C009 JNC C00D D2 If carry flag not set goto label S2.
C00A OD Lower address byte
C00B C0 Upper address byte.
C00C INR B 04 Increment B reg by 1
C00D S2 DCR C OD Decrement C by 1
C00E JNZ C006 C2 If C !=0, then goto label S1
C00F 06 Lower address byte
C010 C0 Upper address byte.
C011 STA C060 32 Store accumulator data to C060
C012 60 Lower address byte
C013 C0 Upper address byte.
C014 MOV A, B 78 Move B contents to A reg.
C015 ADI 00H C6 Add immediate 00 to accumulator
C016 00
C017 DAA 27 Decimal Adjust Accumulator
C018 STA C061 32 Store accumulator data to C061
C019 61 Lower address byte
C01A C0 Upper address byte.
C01B RST 1 CF Stop

C S I I P r a c t i c a l H a n d b o o k P a g e 27 | 34
Details after program execution:

Before Execution After Execution

Memory Location Data Memory Location Data


C0FF(Block Length) 05 C0FF(Block Length) 05
C100 02 C100 02
C101 03 C101 03
C102 05 C102 05
C103 06 C103 06
C104 07 C104 07
C060 23
C061 00

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B C D* E* F H L
00 00 00 00 00 44 C1 04
FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 0 1 0

C S I I P r a c t i c a l H a n d b o o k P a g e 28 | 34
Practical No : 12

Write a program that adds the contents of a block of memory using DAD instruction.
Block length stored at D100 and starting address of block is D101. Store the two byte
result below the end of the block.

Program Steps:-

1. This Program is to do addition between values stored in memory locations with use of DAD
instruction (16 bit addition).
2. First fetch the data from memory location [Link] this initialize HL pointer to D100
location.D100 in having length of the block store it in register A (i.e how many numbers to
be added).
3. Initialize 00 to register pair BC & DE.
4. Increment HL & transfer first number to register C. consider first number is “05”, so BC
value will become “0005”. DE value is “0000” & HL value is “D101”.
5. With XCHG instruction exchange the data of DE & HL, as we are using DAD instruction in
which one number should be there in HL pair. So after exchange HL will have “0000” & DE
will have “D101”.
6. Add the value of BC & HL. Result will be stored in HL register.
BC=0005 (first number) HL= 0000 (Initial value) DE= D101.
Addition result will be HL=HL+BC so HL= 0005.
7. Again exchange the contents of HL & DE. HL will point to next memory.
8. Decrement counter value A. If it is not zero repeat step no 5 to 7 till value of a become
zero.
9. Store the result of addition from register DE to the end of the block.

Program:

Addres
Label Mnemonics HexCode Comment
s
Operan
Opcode
d
C000 START LXI H,D100 21 Initialize HL as a Memory Pointer
C001 00 Lower address byte
C002 D1 Upper address byte.
C003 MOV A, M 7E Move the length of block in A reg.
C004 LXI B,0000 01 Initialize BC reg. to 0000 H
C005 00
C006 00
C007 LXI D ,0000 11 Initialize DE reg. to 0000 H
C008 00
C009 00
C00A V1 INX H 23 Increment HL Pointer by one.
C00B MOV C, M 4E

C S I I P r a c t i c a l H a n d b o o k P a g e 29 | 34
C00C XCHG EB Exchange HL contents with DE
C00D DAD B 09 Add BC contents with HL.
C00E XCHG EB Exchange HL contents with DE

Decrement counter block length by


C00F DCR A 3D
1

If A contents are not zero then go


C010 JNZ C00AH C2
to label V1
C011 0A Lower address byte
C012 C0 Upper address byte.
C013 INX H 23 Increment HL Pointer by 1
Move resultant’s lower byte to
C014 MOV M, E 73
memory location pointed by HL.
C015 INX H 23 Increment HL Pointer by one.
Move resultant’s higher byte to
C016 MOV M, D 72
memory location pointed by HL.
C017 STOP RST 1 CF Stop Program Execution

Details after program execution:

Before Execution After Execution

Memory Location Data Memory Location Data


D100(Block Length) 05 D100(Block Length) 05
D101 01 D101 01
D102 04 D102 04
D103 05 D103 05
D104 06 D104 06
D105 02 D105 02
D106 00 D106 12
D107 00 D107 00

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B C D E F H L
00 00 02 00 12 54 D1 07

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0
Questions:
C S I I P r a c t i c a l H a n d b o o k P a g e 30 | 34
1. Explain working of DAD instructions with example.
2. Why XCHG instruction is used in this program.
3. Explain Flag register.

Practical No: 13

Write a program that uses keyboard subroutine having starting address 02E7 to
accept two digits from the keypad. Store them separately in consecutive memory
locations C030 to C031 and store them as one byte data at memory location C032.

Program:

Addres Label Mnemonics HexCod Comment


s e
Operan
Opcode
d
C000 START LXI SP,C700 31 Initialize SP to C700
C001 00 Lower address byte
C002 C7 Upper address byte.
C003 LXI B,C030 01 Initialize BC to C030
C004 30 Lower address byte
C005 C0 Upper address byte.
Call Keyboard subroutine to
C006 CALL O2E7 CD
accept data from keyboard
C007 E7 Lower address byte
C008 02 Upper address byte.
Move User entered data from
C009 MOV D,A 57
Accumulator to D reg.
Store User entered number
C00A STAX B 02 to memory pointed by BC
pair
C00B INX B 03 IncrementBC by 1.
Call Keyboard subroutine to
C00C CALL 02E7 CD
accept data from keyboard
C00D E7 Lower address byte
C00E 02 Upper address byte.
Store User entered number
C00F STAX B 02 to memory pointed by BC
pair
C010 RLC 07
Rotate Accumulator data to
C011 RLC 07
right for 4 times, to shift
C012 RLC 07
entered number
C013 RLC 07
Add D reg. data to
C014 ADD D 82
accumulator
C015 INX B 03 IncrementBC by 1

Store addition result in


C016 STAX B 02
memory Pointed by BC pair

C S I I P r a c t i c a l H a n d b o o k P a g e 31 | 34
C3017 STOP RST 1 CF Stop program execution

Note:- We are using inbuilt keyboard subroutine in above program to accept data from user
during program execution. Keyboard subroutine is stored at 02E7 memory location (For Dynakit).

Details after program execution:

Before Execution After Execution

Memory Location Data Memory Location Data


No Data E 3
E 2
C030 03
C031 02
C032 23

GENERAL REGISTERS

(* indicates register not used in program .Data after execution for these register can be
changed)

A B C D E F H* L*
23 C0 32 03 85 00 FF FE

FLAG REGISTER

D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 0 0 0 0

Question:- 1. Explain CALL instruction.

C S I I P r a c t i c a l H a n d b o o k P a g e 32 | 34
Practical No: 14

Write a program for using the microprocessor kit as a calculator that would accept
number & display the sum. Use monitor routines to input the numbers & output the
numbers to the display.
Program:

Addres HexCod
Label Mnemonics Comment
s e
Opcod Operan
e d
C000 START LXI SP,C700 31 Initialize stack pointer at stack
C001 00 Lower address byte
C002 C7 Upper address byte.
Call keyboard monitor routine
C003 CALL O2E7 CD
called RDKBD
C004 E7 Lower address byte
C005 02 Upper address byte.
C006 MOV D,A 57 Store A contents to D
Call keyboard monitor routine
C007 CALL O2E7 CD
called RDKBD
C008 E7 Lower address byte
C009 02 Upper address byte.
C00A ADD D 82 Add D contents with A.
Decimally adjust the
C00B DAA 27
accumulator
Call monitor routine called
C00C CALL 036E H CD
which display’s A [Link]
C00D 6E Lower address byte
C00E O3 Upper address byte.
C00F JMP C003 C3 Jump unconditionally
C010 O3 Lower address byte
C011 C0 Upper address byte.

Note:- We are using inbuilt keyboard subroutine in above program to accept data from user
during program execution. Keyboard subroutine is stored at 02E7 memory location (For Dynakit).
We are also using display subroutine to display output on 7 segment display. Display subroutine
is stored at 036E memory location.

Details after program execution:


Before Execution After Execution
C S I I P r a c t i c a l H a n d b o o k P a g e 33 | 34
Memory Data Memory Location Data
Location
E 7
E 6
OUTPUT ON 13
DISPLAY

C S I I P r a c t i c a l H a n d b o o k P a g e 34 | 34

You might also like