MICROPORCESSOR 8085 Lab Manual
MICROPORCESSOR 8085 Lab Manual
MICROPORCESSOR 8085 Lab Manual
SUBJECT:
MICROPROCESSOR &
MALPINDEX
MICROPROCESSOR & INTRAFACING
SR.NO.
1
2
3
4
5
6
7
8
10
11
12
13
14
15
16
17
AIM
DATE
TO STUDY THE ARCHITECTURE OF 8085
TO STUDY THE TIMING DIAGRAM OF 8085
TO STUDY THE DEMULTIPLEXING OF
CONTROL SIGNALS
TO STUDY THE INSTRUCTIONS OF 8085
PERFORM A PROGRAM TO ADD TWO 8
BIT NUMBERS USING 8085 SIMULATOR
PERFORM A PROGRAM TO SUBTRACT
TWO 8 BIT NUMBERS USING 8085
SIMULATOR
PERFORM A PROGRAM TO ADD TWO 16
BIT NUMBERS USING 8085 SIMULATOR
PERFORM A PROGRAM TO MULTIPLY
TWO 8 BIT NUMBERS USING SUCCESSIVE
ADDITION
METHOD
USING
8085
SIMULATOR
PERFORM A PROGRAM TO MULTIPLY
TWO BIT NUMBERS USING SHIFT AND ADD
METHOD USING 8085 SIMULATOR
PERFORM A PROGRAM TO DIVIDE 16 BIT
NUMBER BY AN 8 BIT NUMBER USING 8085
SIMULATOR
PERFORM A PROGRAM TO ADD TWO 16
BIT
BCD
NUMBERS
USING
8085
SIMULATOR
PERFORM A PROGRAM TO TRANSFER A
BLOCK OF N BYTES FROM SOURCE TO
DESTINATION USING 8085 SIMULATOR
PERFORM A PROGRAM TO PROGRAM TO
FIND MAXIMUM NUMBER IN THE ARRAY
USING 8085 SIMULATOR
PERFORM A PROGRAM TO PROGRAM TO
FIND MINIMUM / SMALLEST NUMBER IN
ARRAY USING 8085 SIMULATOR
PROGRAM TO SORT THE NUMBERS IN
ASCEDING ORDER
PROGRAM TO SORT THE NUMBERS IN
DESCEDING ORDER.
INTRODUCTION TO 8085
MICROPROCESSOR TRAINER KIT VMC8501
2
SIGNATURE
MALP-
MALPPRACTICAL-1
AIM : To study about 8085 microprocessor Architecture.
Control Unit
Generates signals within up to carry out the instruction, which has been decoded. In reality
causes certain connections between blocks of the up to be opened or closed, so that data goes
where it is required, and so that ALU operations occur.
Arithmetic Logic Unit
The ALU performs the actual numerical and logic operation such as add, subtract,
AND, OR, etc. ALU uses data from memory and from Accumulator to perform arithmetic
operations. Always stores result of operation in Accumulator.
Registers
The 8085/8080A-programming model includes six registers, one accumulator, and one flag
register, as shown in Figure. In addition, it has two 16-bit registers: the stack pointer and the
program counter. They are described briefly as follows.
The 8085/8080A has six general-purpose registers to store 8-bit data; these are identified as
B,C,D,E,H, and L as shown in the figure. They can be combined as register pairs - BC, DE, and
HL - to perform some 16-bit operations. The programmer can use these registers to store or
copy data into the registers by using data copy instructions.
Accumulator
The accumulator is an 8-bit register that is a part of 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. The accumulator is also identified as register A.
4
MALP-
Flags
The ALU includes five flip-flops, which are set or reset after an operation according to data
conditions of the result in the accumulator and other registers. They are called Zero (Z), Carry
(CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags; they are listed in the Table and their
bit positions in the flag register are shown in the Figure below. The most commonly used flags
are Zero, Carry, and Sign. The microprocessor uses these flags to test data conditions.
For example, after an addition of two numbers, if the sum in the accumulator id larger than
eight bits, the flip-flop uses to indicate a carry -- called the Carry flag (CY) -- is set to one.
When an arithmetic operation results in zero, the flip-flop called the Zero (Z) flag is set to one.
The first Figure shows an 8-bit register, called the flag register, adjacent to the accumulator.
However, it is not used as a register; five bit positions out of eight are used to store the outputs
of the five flip-flops. The flags are stored in the 8-bit register so that the programmer can
examine these flags (data conditions) by accessing the register through an instruction. These
flags have critical importance in the decision-making process of the micro- processor. The
conditions (set or reset) of the flags are tested through the software instructions. For example,
the instruction JC (Jump on Carry) is implemented to change the sequence of a program when
CY flag is set. The thorough understanding of flag is essential in writing assembly language
programs.
Program Counter (PC)
This 16-bit register deals with sequencing the execution of instructions. This register is a
memory pointer. Memory locations have 16-bit addresses, and that is why this is a 16-bit
register. The microprocessor uses this register to sequence the execution of the instructions. 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 (machine code) is being fetched, the program counter is incremented by
one to point to the next memory location.
Stack Pointer (SP)
The stack pointer is also a 16-bit register used as a memory pointer. It points to a memory
location in R/W memory, called the stack. The beginning of the stack is defined by loading 16bit address in the stack pointer. The stack concept is explained in the chapter "Stack and
Subroutines."
Interrupts
The 8085 microprocessor has 5 interrupts. They are presented below in the order of their
priority (from lowest to highest):
INTR is maskable 8080A compatible interrupt. When the interrupt occurs the processor fetches
from the bus one instruction, usually one of these instructions:
One of the 8 RST instructions (RST0 - RST7). The processor saves current program
counter into stack and branches to memory location N * 8 (where N is a 3-bit number
from 0 to 7 supplied with the RST instruction).
5
MALP
CALL instruction (3 byte instruction). The processor calls the subroutine, address of
which is specified in the second and third bytes of the instruction.
RST5.5 is a maskable interrupt. When this interrupt is received the processor saves the contents
of the PC register into stack and branches to 2Ch (hexadecimal) address.
RST6.5 is a maskable interrupt. When this interrupt is received the processor saves the contents
of the PC register into stack and branches to 34h (hexadecimal) address.
RST7.5 is a maskable interrupt. When this interrupt is received the processor saves the contents
of the PC register into stack and branches to 3Ch (hexadecimal) address.
Trap is a non-maskable interrupt. When this interrupt is received the processor saves the
contents of the PC register into stack and branches to 24h (hexadecimal) address.
All maskable interrupts can be enabled or disabled using EI and DI instructions. RST 5.5,
RST6.5 and RST7.5 interrupts can be enabled or disabled individually using SIM instruction.
Pin Diagram of 8085 Microprocessor with Description
1.Power Supply
2.Clock Signals
3.Interrupt Signals
4.Address and Data bus
5.Control and Status signals
6.Serial I/O Port
7.DMA Request Signals
MALP-
MALPPRACTICAL-2
AIM: To study the Timing Diagram of 8085 Microprocessor.
Timing Diagram is a graphical representation. It represents the execution time taken by each
instruction in a graphical format. The execution time is represented in T-states.
Instruction Cycle:
The time required to execute an instruction is called instruction cycle.
Machine Cycle:
The time required to access the memory or input/output devices is called machine cycle.
T-State:
The machine cycle and instruction cycle takes multiple clock periods.A portion of an operation
carried out in one system clock period is called as T-state.
MALP-
Each instruction of the 8085 processor consists of one to five machine cycles, i.e., when the
8085 processor executes an instruction, it will execute some of the machine cycles in a specific
order.
The processor takes a definite time to execute the machine cycles. The time taken by the
processor to execute a machine cycle is expressed in T-states.
One T-state is equal to the time period of the internal clock signal of the processor.The T-state
starts at the falling edge of a clock.
Opcode fetch machine cycle of 8085 :
Each instruction of the processor has one byte opcode. The opcodes are stored in memory. So,
the processor executes the opcode fetch machine cycle to fetch the opcode from memory. Hence,
every instruction starts with opcode fetch machine cycle. The time taken by the processor to execute
the opcode fetch cycle is 4T. In this time, the first, 3 T-states are used for fetching the opcode from
memory and the remaining T-states are used for internal operations by the processor.
10
MALP-
Examples with Instruction: Every Instruction has timing diagram that depends on its T-state.
1) MVI B, Data
11
MALP-
2) STA , address
CONCLUSION :
12
MALP-
PRACTICAL-3
AIM: To study the de-multiplexing of control signals in 8085.
Demultiplexing means separation of address/data bus AD0-AD7 into address bus AD7
AD0 and data bus D7D0. Microprocessor 8085 is having AD 0AD7. Bus which is used for
sending lower 8 bit address as well as data. During last clock cycle, address is transferred on these
lines and data during 2nd clock cycle and 3rd clock cycle. Therefore during the 1st clock cycle lower
address must be transferred on AD 0AD7. For this purpose, in the 1 st clockcycle ALE is high and
latch is enabled. So the address available at A0 A7. During the 2nd and 3rd clock cycle ALE goes
low and latch is disabled. So ADoAD7 will act as D0D7 in the 2nd and 3rd clock cycle.
Microprocessor will transfer 16 bit addresses from PC to address lines, So the desired
memory location is selected.
Microprocessor then gives location RD=0. So, the 8 bit instruction bit code is transferred
from selected memory location to data pins.
13
MALP
This instruction code is transferred by Microprocessor from data bus to instruction register.
This method of transferring instruction opcode from memory to instruction register is called as
Opcode fetch instruction.
Execution Operation:
The instruction code is transferred from Instruction register to Instruction decoder. Hence
one corresponding clock at the instruction decoder output executes. The clock will generate
all the control signal to execute one corresponding instruction.
If the instruction code is of 2/3 Bytes, then first this clock will read second and third byte of
instruction from memory and then execute the corresponding instruction. The address in the
PC is auto incremented by one. The same process of fetch and execution is repeated for next
instruction code.
CONCLUSION:
14
MALP-
PRACTICAL- 4
Aim : To Study about 8085 Instruction Set.
The 8085 instructions can be classified as follows:
Operand
Load accumulator
LDA
16-bit address
Description
This instruction copies the contents of the source
register into the destination register; the contents of
the source register are not altered. If one of the operands is a
memory location, its location is specified by the contents of
the HL registers.
Example: MOV B, C or MOV B, M
The 8-bit data is stored in the destination register or
memory. If the operand is a memory location, its location is
specified by the contents of the HL registers.
Example: MVI B, 57H or MVI M, 57H
The contents of a memory location, specified by a
16-bit address in the operand, are copied to the accumulator.
The contents of the source are not altered.
Example: LDA 2034H
The contents of the designated register pair point to a memory
location. This instruction copies the contents of that memory
location into the accumulator. The contents of either the
register pair or the memory location are not altered.
Example: LDAX B
The instruction loads 16-bit data in the register pair
designated in the operand.
Example: LXI H, 2034H or LXI H, XYZ
LHLD 16-bit address
MALP-
16
The contents of register L are stored into the memory location specified by the 16-bit address in the
operand and the contents of H register are stored into the next memory location by incrementing the
operand. The contents of registers HL are not altered. This is a 3-byte instruction, the second byte
specifies the low-order address and the third byte specifies the high-order address.
Example: SHLD 2470H
Exchange H and L with D and E
XCHG
ARITHMETIC INSTRUCTIONS
Opcode
Operand
Description
18
19
Decrement register or memory by 1 The contents of the designated register or memory are
DCR R
decremented by 1 and the result is stored in the same place. If
M
the operand is a memory location, its location is specified by
the contents of the HL registers.
Example: DCR B or DCR M
Decrement register pair by 1
DCX R
BRANCHING INSTRUCTIONS
Opcode
Operand
Description
Jump unconditionally
JMP
16-bit address
Jump conditionally
16-bit address
The program sequence is transferred to the memory location
specified by the 16-bit address given in the operand based on
the specified flag of the PSW as described below.
Example: JZ 2034H or JZ XYZ
Opcode
JC
JNC
JP
JM
JZ
JNZ
JPE
JPO
Description
Jump on Carry
Jump on no Carry
Jump on positive
Jump on minus
Jump on zero
Jump on no zero
Jump on parity even
Jump on parity odd
Flag Status
CY = 1
CY = 0
S=0
S=1
Z=1
Z=0
P=1
P=0
Call conditionally
Operand: 16-bit address
The program sequence is transferred to the memory location
specified by the 16-bit address given in the operand based on
the specified flag of the PSW as described below. Before the
transfer, the address of the next instruction after the call (the
contents of the program counter) is pushed onto the stack.
Example: CZ 2034H or CZ XYZ
Opcode
CC
CNC
CP
CM
CZ
CNZ
Description
Call on Carry
Call on no Carry
Call on positive
Call on minus
Call on zero
Call on no zero
Flag Status
CY = 1
CY = 0
S=0
S=1
Z=1
Z=0
CPE
CPO
P=1
P=0
Restart Address
0000H
0008H
0010H
0018H
0020H
0028H
0030H
0038H
The 8085 has four additional interrupts and these interrupts generate RST instructions internally and
thus do not require any external hardware. These instructions and their Restart addresses are:
Interrupt
TRAP
RST 5.5
RST 6.5
RST 7.5
Restart Address
0024H
002CH
0034H
003CH
LOGICAL INSTRUCTIONS
Opcode
Operand
Description
CONTROL INSTRUCTIONS
Opcode
Operand
No operation
NOP
Description
No operation is performed. The instruction is fetched and
decoded. However no operation is executed.
Example: NOP
Halt and enter wait state HLT
Enable interrupts
EI
conclusion:
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
PROGRAM: 5
ADDITION OF TWO 8 BIT NUMBERS.
PROGRAM STATEMENT:
Write a program to add the contents of memory locations D000H and D001H. Store result in
memory location D002H.
EXPLANATION:
We have two numbers at memory locations D000H and D001H. Let these numbers be
20H and 23H. We have to add these two numbers.
Using ADD instruction we will add the two numbers.
Store the result at memory location D002H.
e.g.
D000H = 20H
D001H = 23H
Result D002H = 20H + 23H = 43H
PROGRAM:
INSTRCTIO
N
LXI H, D000H
MOV A, M
INX H
ADD M
INX H
MOV M, A
HLT
COMMENT
OPERATION
H = D0H
L = 00H
Load first operand in accumulator
A = 20H
Increment HL to point next memory location i.e. H = D0H,
D001H
L = 01H
D001 : 23H
Add the second operand with first operand.
A=A+ M
A = 20 + 23
A = 43 H
Increment HL to point to next memory location
H = D0H,
L = 02H
Store the result
D002 : 43H
Result
Terminate program execution
Stop.
27
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
FLOWCHART:
Star
t
Set HL as
memory pointer
at memory
location
Load the
number in
accumulator
Increment
pointer to point
to the second
number
Increment
pointer and
store the result
HL = D000H
A = 20H
HL = D001
A = 43H
D002: 43
Result
Stop
28
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
PROGRAM: 6
SUBTRACTION OF TWO 8 BIT NUMBERS.
PROGRAM STATEMENT:
Write a program to subtract the contents of memory locations D001H from memory location
D000H and place the result in memory location D002H.
EXPLANATION:
We have two numbers at memory locations D000H and D001H. Let these numbers be
50H and 20H. We have to subtract these two numbers.
Using SUB instruction we will subtract the two numbers.
Store the result at memory location D002H.
e.g.
D000H = 50H
D001H = 20H
Result D002H = 50H - 20H = 30H
PROGRAM:
INSTRCTIO
N
LXI H, D000H
MOV A, M
INX H
SUB M
INX H
MOV M, A
HLT
COMMENT
OPERATION
H = D0H
L = 00H
Load first operand in accumulator
A = 50H
Increment HL to point next memory location i.e. H = D0H,
D001H
L = 01H
D001 : 20H
Subtract the second operand with first operand.
A=A M
A = 50 20
A = 30 H
Increment HL to point to next memory location.
H = D0H,
i.e. D002H
L = 02H
Store the result
D002 : 30H
Result
Terminate program execution
Stop.
29
GP GANDHINAGAR
EC DEPARTMENT
(SEM-4)
FLOWCHART:
Star
t
Set HL as
memory pointer
at memory
location
Load the
number in
accumulator
HL = D000H
A = 50H
Increment
pointer to point
to the second
number
HL = D001
A = 30H
Increment
pointer and
store the result
D002: 30
30
MALP-3341101
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Stop
PROGRAM: 7
ADDITION OF TWO 16 BIT NUMBERS.
PROGRAM STATEMENT:
Write a program to add the 16 bit number in memory locations D000H and D001H with the 16
bit number in memory locations D002H and D003H. The most significant 8 bits of the two
numbers to be added are in memory locations D001H and D003H. Store the result in memory
locations D004H and D005H with the most significant byte in memory location D005H.
EXPLANATION:
We have two16 bit numbers. Let the two numbers be 1234H and 4321H.
We have to add the word at memory locations D000H and D001H with the word at
memory locations D002H and D003H.
For computing the addition there are two methods.
We will store the two numbers in the register pairs DE and HL. Then using the DAD
instruction we will add the two 16 bit numbers. The result of addition will be stored in the
HL register pair. Store the result.
e.g. D000H = 34H
D001H = 12H
D002H = 21H
D003H = 43H
RESULT = 1234H + 4321H = 5555H
D004H = 55H
D005H = 55H
PROGRAM:
INSTRCTIO
N
LHLD D000H
XCHG
LHLD D002H
DAD D
COMMENT
OPERATION
SHLD D004H
H = 12H, L = 34H
D = 12H, E = 34H
H = 43H, L = 21H
HL = HL + DE
HL = 4321 + 1234
HL = 5555H
H = 55H, L = 55H
D004H : 55H
D005H : 55H
31
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
HLT
Result
Stop
FLOWCHART:
Star
t
Load the first 16
bit number and
store it in a
separate
register
H = 12H
L = 34H
D = 12H
E = 34H
H = 43H
L -34H
HL = 1234 +
4321
HL = 5555H
D004H: 55H
D005H: 55H
Result
Stop
32
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
PROGRAM: 8
MULTIPLY TWO 8 BIT NUMBERS USING SUCCESSIVE ADDITION METHOD.
PROGRAM STATEMENT:
Multiply two 8 bit numbers stored in memory locations D000H and D001H. Store the result in
memory locations E000H and E001H.
EXPLANATION:
Consider that a byte is present at the memory location D000H and second byte is
present at memory location D001H.
We have to multiply the bytes present at the above two memory locations.
We will multiply the numbers using successive addition method.
In successive addition method, one number is accepted and other number is taken as a
counter. The first number is added with itself, till the counter decrements to zero.
Result is stored at memory locations E000H and E001H.
For example: D000H = 12H,D001H = 10H
Result = 12H + 12H + 12H + 12H + 12H + 12H + 12H + 12H + 12H + 12H
Result = 0120H
E000H = 20H
E001H = 01H
PROGRAM:
Label
Instruction
LDA
D000H
MOV E, A
MVI
D,
00H
LDA
D001H
MOV C , A
Comment
A = first number
Operation
A = 12H
E = first number
D = 00H
E = 12H
D = 00H
A = second number
A = 10H
Initialize counter
C = 10H
33
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
BACK
:
LXI
H, Result = 0
0000H
DAD D
Result = result + first number
DCR C
JNZ BACK
SHLD
E000H
Decrement count
If counter 0 repeat
Store result
HLT
FLOWCHART:
Start
Initialize Result = 0
Decrement counter
No
Is counter = 0?
Yes
Store result
34
Stop
H = 00H,
L = 00H
HL = HL +
DE
C=C1
E000H
:
20H,
E001H : 01H
Result
Stop
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
PROGRAM: 9
WRITE A PROGRAM TO MULTIPLY TWO BIT NUMBERS USING SHIFT AND ADD
METHOD.
DEFINITION:
Input: 2 data bytes directly available
Operation: Multiply and.
Output: Store the result in HL pair
SOLUTION PLAN:
1. Load 2 data bytes in registers.
2. The data is of 8 bits, use it as counter.
3. Shift and add method so use register pair to store result. The method is as follows :
number 1 * number 2 both of 8 bits,
If we observe the above example carefully we get following points:
(i)
If the bit is 1 we add to the result.
(ii)
After each checking and adding we have to shift result to left by 1 bit.
4. The result is of 16 bits so use HL pair as result register.
5. To shift result left by 1 bit add the same contents (i.e.) it will shift all bits left by 1 bit.
6. If the bit is 1, add to result. Then shift the result to left by 1 bit. Check the next bit and so
on up to end.
PROGRAM:
Label
Instruction
LXI
D,
multiplicand
LXI H, 0000H
MVI B, multiplier
Operation
Number 1
DE
000
HL (Result reg.)
Number 2
B
35
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
UP:
DOWN:
MVI C, 08H
DAD H
MOV A, B
RLC
MOV B, A
JNC DOWN
DAD D
DCR C
JNZ UP
FLOWCHART:
08
C (counter)
HL + HL HL (shift result left by 1
bit)
B
A
Rotate data to left by 1 bit
A
B
Is bit = 1, if no go to down
HL + DE HL
C1
C
Is C = 0,
Start
No Is carry = 1?
Yes
Result = result + no1
Counter = counter 1
36
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Is counter = 0?
No
Yes
Stop
PROGRAM: 10
DIVIDE 16 BIT NUMBER BY AN 8 BIT NUMBER.
PROGRAM STATEMENT:
Divide 16 bit number stored in memory locations D000H and D001H by the 8 bit number stored
at memory location D002H. Store the quotient in memory locations E000H and E001H and
remainder in memory locations E002H and E003H.
EXPLANATION:
Get the dividend in the HL register pair. Get the divisor in the accumulator and store it in
register C.
Initialize quotient in register pair DE as 00H.
Perform the division by subtracting the divisor from the dividend, till the dividend is
greater than the divisor. Increment the quotient every time the dividend is greater than the
divisor when the subtraction is performed.
When the dividend becomes less than the divisor then this dividend is the remainder.
Store the quotient and remainder.
EXAMPLE:
D000 = 05H
D001H = 02H
D002H = 04H
Result = 0205H/04H
= 81H (Quotient)
And 01H = Reminder
E000H = 81H
37
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
E001H = 00H
E002H = 01H
E003H = 00H
PROGRAM:
Label
BACK:
SKIP:
Instruction
LHLD D000H
Comment
Get the dividend
LDA D002H
MOV C,A
LXI D, 0000H
MOV A,L
SUB C
MOV L,A
JNC SKIP
DCR H
INX D
MOV A,H
CPI 00
JNZ BACK
MOV A,L
CMP C
JNZ BACK
SHLD E002H
Operation
H = 02H, L =
05H
A = 04H
C = 04H
D = 00H, E =
00H
A=L
A= A C
L=A
previous H = H 1
DE = DE + 1
A=H
A=L
E002H = 01H,
E003H = 00H
(Reminder)
Result
XCHNG
38
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
SHLD E000H
HLT
FLOWCHART:
Start
If Dividend <
No
divisor
39
E000H = 81H,
E001H = 00H
(Quotient) Result
Stop
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Yes
Reminder = Dividend
Store the quotient and reminder
Stop
PROGRAM: 11
ADD TWO 16 BIT BCD NUMBERS.
PROGRAM STATEMENT:
Add two 4 digits BCD numbers in HL and DE register pairs and store the result in memory
locations D000H and D001H with the MSB loaded at D001H. Ignore carry after 16 bit.
EXPLANATION:
Consider that two words are available in register pairs HL and DE. We have to add these
two words.
Using add instruction, add the contents, of the lower two bits i.e. add L and E.
The result of this addition is stored in the A register.
DAA instruction is then used to convert the result to valid BCD. Store the result at
memory location D000H.
Now, add the contents of MSB along with carry if generated in LSB addition.
The result of MSB addition is stored in the A register. Adjust this result to valid BCD
number. The final result is then stored at the memory location D001H.
e.g.: HL
=
3629 BCD
DE
=
4738 BCD
ALGORITHM:
Step 1 :
Add two lower digits.
Step 2 :
Adjust result to valid BCD number.
40
GP GANDHINAGAR
EC DEPARTMENT
(SEM-4)
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
:
:
:
:
:
:
PROGRAM:
INSTRUCTIO
N
MOV A,L
ADD E
DAA
STA D000H
MOV H,A
ADC D
DAA
STA D001H
HLT
COMMENT
Get the LSB of first number in A
A = A + E i.e. compute the LSB addition
Convert the HEX to valid BCD result
Store result of LSB addition at location
D000H
Get the MSB of first number in A
A = A + D i.e. compute the MSB addition
Convert the HEX to valid BCD result
Store result of LSB addition at location
D001H
Terminate the execution of program
FLOWCHART:
Start
MALP-3341101
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
PROGRAM: 12
TRANSFER A BLOCK OF N BYTES FROM SOURCE TO DESTINATION
PROGRAM STATEMENT:
Write an ALP to move a block of N bytes of data from source block to destination block. Source
memory location D000H and destination memory block starts from E000H.
EXPLATION:
Consider that a block of data of N bytes is present at source location. Now this block of N
bytes is to be moved from source location.
Let the number of bytes N = 10.
We will have to initialize this as count in the C register.
We know that source address is in the HL register and destination address is in the DE
register.
Get the byte from source memory block and store the byte in the destination memory
block.
Transfer data byte by byte from source to destination block till all the bytes are
transferred.
PROGRAM:
42
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Label
Instruction
MVI C, 0AH
LXI H, D000H
LXI D, E000H
BACK:
MOV A, M
SATX D
INX H
INX D
DCR C
JNZ BACK
HLT
FLOWCHART:
Comment
Initialize counter
Initialize source memory pointer
Operation
C = 0AH
H = D0H,
L = 00H
Initialize destination memory pointer
D = E0H,
E = 00H
Get byte from source memory block
M
A
Store byte in the destination memory Result
block
Increment source memory pointer
HL = HL + 1
Initialize destination memory pointer
DE = DE + 1
Decrement counter
C=C1
If counter 0 repeat
Terminate program execution
Stop
Start
Initialize count in C = 10
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
NoIs count = 0?
Yes
End
PROGRAM 13:
PROGRAM TO FIND MAXIMUM NUMBER IN THE ARRAY.
PROGERAM STATEMENT:
Given an array of numbers. Write a program in ALP of 8085 to find the maximum number
amongst the numbers in the array. Assume that the length of array is stored at memory location
D000H and the array beings from memory location D001H. Store the maximum number at
memory location E000H.
EXPLANATION:
For example: we have an array of 10 numbers. So we initialize the counter with 10. Also
we initialize a pointer to point these numbers.
Compare first number with initial maximum number, save number otherwise increment
pointer to compare next number. Decrement counter, compare till all the numbers are
compared. Store the maximum number in memory location E000H.
PROGRAM:
44
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Label
BACK
SKIP:
Instruction
LDA D000H
MOV C, A
XRA A
LXI
H,
D001H
CMP M
JNC SKIP
MOV A,M
Comment
Load accumulator with count
Initialize counter
Initialize A = 0
Initialize memory pointer
Is number > maximum
INX H
DCR C
JNZ BACK
STA E000H
HLT
FLOWCHART:
Operation
A = 10H
C = 10H
A = 00H
H = D0H, L = 01H
Start
Initialize pointer
Initialize counter = 10
Initialize base pointer for array
Is Num > Max?
No
Yes
Save the number
45
then
HL = HL + 1
C=C1
E000H: Max. number
Result
Stop
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Increment pointer
Decrement counter
Is count = 0?
No
Yes
Store the result at location E000H
Stop
PROGRAM: 14
PROGRAM TO FIND MINIMUM / SMALLEST NUMBER IN ARRAY.
PROGRAM STATEMENT:
Given an array of numbers. Write a program in ALP of 8085 to find the maximum number
amongst the numbers in the array. Assume that the length of array is stored at memory location
D000H and the array beings from memory location D001H. Store the maximum number at
memory location E000H.
EXPLANATION:
We have an array of 10 numbers for e.g. so we initialize the counter with 10. Also we
initialize a pointer to point these numbers.
Compare first number with initial number. If number < minimum number, save otherwise
increment pointer to compare next number. Decrement counter, compare till all the
numbers are compared. Store the maximum number in memory location E000H.
46
GP GANDHINAGAR
EC DEPARTMENT
(SEM-4)
PROGRAM:
Label
BACK:
SKIP:
Instruction
LDA D000H
MOV C, A
LXI H, D001H
MOV A, M
INX M
CMP M
JC SKIP
MOV A,M
Comment
Load counting accumulator
Initialize counter
Initialize memory pointer
Increment memory pointer
Is number < minimum
If number < minimum then
interchange
Increment memory pointer
Decrement counter
If count 0 repeat
Store minimum number
Terminate program execution
INX H
DCR C
JNZ BACK
STA E000H
HLT
FLOWCHART:
Start
Initialize pointer
Initialize counter = 10
Initialize base pointer for array
Is Num < min?
No
47
MALP-3341101
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Yes
Save the number
Increment pointer
Decrement counter
Is count = 0?
No
Yes
Store the result at location E000H
Stop
PROGRAM: 15
PROGRAM TO SORT THE NUMBERS IN ASCEDING ORDER.
PROGRAM STATEMETNT:
Write a program in assembly language of 8085 to sort the given N numbers from a block in
ascending order. Assume that the memory block beings at D000H.
EXPLANATION:
Consider that a block of N words is present. Now we have to arrange these N words in
ascending order, Let N = 4 for example. We will use HL as pointer to point the block of N
words.
48
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
Initially in the first iteration we compare first number with the second number. If first
number < second number, dont interchange the contents, otherwise if first number >
second number swap the contents.
In the next iteration we go on comparing the first number with third number. If first
number < third number, dont interchange the contents.
If first number > third number then swapping will be done.
Since the first two numbers are in ascending order the third number will go to first place,
first number in second place and second number will come in third place in the second
iteration only if first number > third number.
In the next iteration first number is compared with fourth number. So comparisons are
done till all N numbers are arranged in approximately n comparisons.
PROGRAM:
Label
Instruction
START
MVI B, 09
LXI H, D000H
BACK:
MVI C, 09H
MOV A, M
INX H
CMP M
JC SKIP
JZ SKIP
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
SKIP:
DCR C
JNZ BACK
DCR B
JNZ START
HLT
Comment
Initialize counter 1
Initialize memory pointer
Operation
B = 09H
H = D0H
L = 00H
Initialize counter 2
C = 09H
Get the number in accumulator
A M
Increment memory pointer
HL = HL +1
Compare number with next number
Compare
If less, dont interchange
If A < M dont
interchange
If equal, dont interchange
If A = M dont
interchange
Otherwise swap the contents
DM
MA
Interchange numbers
HL = HL 1
MD
Increment pointer to next memory HL = HL + 1
location
Decrement counter2
C=C1
If not zero, repeat
Decrement counter1
B=B1
If not zero, repeat
Terminate program execution
Stop
49
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
PROGRAM: 16
PROGRAM TO SORT THE NUMBERS IN DESCEDING ORDER.
PROGRAM STATEMETN:
Write a program in assembly language of 8085 to sort the given N words from a block in
descending order. Assume that the memory block beings at D000H.
EXPLANATION:
Consider that a block of N words is present.
Now we have to arrange these N number in descending order, Let N = 4 for example.
50
GP GANDHINAGAR
EC DEPARTMENT
MALP-3341101
(SEM-4)
51
GP GANDHINAGAR
EC DEPARTMENT
(SEM-4)
52
MALP-3341101
GP GANDHINAGAR
EC DEPARTMENT
(SEM-4)
1.
2.
3.
4.
5.
6.
Reset
Exmem
Starting Address
Opcode
Next
Continue upto end of the program
Reset
Go
Starting Address
Fill
53
MALP-3341101