Professional Documents
Culture Documents
Cs 2 Practicals
Cs 2 Practicals
Cs 2 Practicals
1. Introduction to microprocessor.
2. 8085 microprocessor instruction set.
3. Addition of two 8 bit numbers.
4. Addition of two 8 bit BCD numbers.
5. Program to multiply two 1 byte hex numbers.
6. Program to add the BCD contents of a block of memory.
7. Program to divide tow 1 byte hex numbers.
8. Program to find smallest as well as greatest number.
9. Program to find odd as well as even numbers.
10. Program to subtract two numbers.
11. Program to find the first occurrence of data in a given block.
12. Program to find how many times data appears in a block.
13. Program to count zero in a given number.
14. Program to exchange the contents of two blocks stored in different
memory locations
15. Program to transfer data in a reverse order.
Practical No.3
Write a program to do addition between two 8 bit numbers. Two numbers are
stored 8030H and 8031H. Store the result in 8032H.
Program Steps
1. Start
2. First fetch data from memory location 8030. For this, initialize HL
pointer to 8030.
3. When HL pair pointers to memory location, data can be fetched with the
use of memory variable M. therefore transfer the data from M to register
A (accumulator).
4. Increment HL pointer by one. So it points to next memory location i.e
8031.
5. Now data of 8031 can be taken by memory variable M.
6. Add Accumulator data and memory variable M.
7. Store the accumulator result in memory location 8032.
8. Stop
Flowchart
Start
Stop
Program
Opcode operand
800 START LXI H,8030 21 Initialize HL pair to
8030.
8001 30 Lower address byte
8002 80 Upper address byte
8003 MOV A,M 7E Move data of 8030 to
Register A
8004 INX H 23 Increment value of HL
pair by one.
8005 ADD M 86 Add accumulator data
with value at HL
pointer.
8006 STA 8032 32 Store Accumulator
result into 8032
8007 32 Lower address byte
8008 80 Upper address byte
8009 STOP RST 1 CF Stop Program
Execution
Before Execution
Memory Location Data
8030 5
8031 6
8032 00
After Execution
A B* C* D E H L F
0B 00 00 00 00 80 31 00
Flag Registers
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 0 0 0 0
Practical No.4
Write a program to do the addition between two 8 bits BCD numbers. Two
numbers are stored in 8030H and 8031H. Store the result in 8032H onwards
starting with least significant bit.
Program Steps
1. Start
2. Initialize HL pointer to 8030
3. Initialize C Reg. to zero
4. Fetch data from memory location 8030 with memory variable M
5. Move M into A Reg.
6. Add A Reg. (Accumulator) with memory variable M.
7. Decimal Adjust Accumulator
8. If carry not generated then
a. Goto step 10
9. Increment C Reg. by one
10. Store the accumulator result in memory location 8032.
11. Move C Reg. data to accumulator.
12. Store the accumulator result in memory location 8033.
13. Stop
Flowchart
Start
Initialize C Reg. to 0
Initialize HL as pointer to
8030
Increment HL by one
Decimal Adjust
Accumulator
Yes
If cy=0 Store the accumulator result
in memory location 8032
After Execution
General Registers
* - Indicates register not used in program
A B* C D* E* F H L
00 00 00 00 00 10 80 31
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 0 1 0 0
Practical No. 5
Write a program that multiples two 1 byte hex numbers stored in consecutive
memory locations starting from 8030. Store the two byte result in consecutive
memory locations starting from 8032 beginning with low order byte.
Program Steps
1. Start
2. Initialize A & B register to zero.
3. Fetch data from memory location 8030. For this, initialize HL pointer to
8030.
4. Move memory variable M (length of block) into C reg.
5. Increment HL pointer by one. So it points to memory location 8031.
6. Add Memory variable M to Accumulator.
7. If carry=0 then
a. Goto step 9
8. Increment B reg. by one
9. Decrement C reg by one
10. If C reg is not zero then
a. Goto step 6
11. Increment HL by one.
12. Move result from Accumulator to memory location pointed by HL.
13. Increment HL by one.
14. Move carry from B Reg. to memory location pointed by HL.
15. Stop
Flowchart Start
Increment HL by one
Move Length of block in
C Reg
Move carry from B Reg to
memory location pointed by HL
Increment HL by one
Stop
No
Increment BReg by 1 If c=0
No
Yes
Program
Opcode Operand
Write a program that adds the BCD contents of a block of memory. Block
length in hex not exceeding 63H=9910 is stored at 80FF and starting address of
block is 8100H. Store the BCD sum as result starting from memory location
8060 H.
Program Steps
1. Start
2. Initialize A & B register to zero.
3. Fetch data from memory location 80FF. For this, initialize HL pointer to
80FF.
4. Move memory variable M (length of block) into C reg.
5. Increment HL pointer by one. So it points to memory location 8100.
6. Decimal Adjust Accumulator.
7. If carry=0 then
a. Goto step 5
8. Increment B reg. by one.
9. Decrement C reg by one.
10. If C reg is not zero then
a. Goto step 5
11. Move result from Accumulator to memory location 8060.
12. Move B reg to A Reg.
13. Add 0 to Accumulator.
14. Decimal Adjust Accumulator.
15. Move result from Accumulator to memory location 8061.
16. Stop
Flowchart
Start
Increment HL by one
Store accumulator result in memory
location poinerd by HL i.e 8061
No
Increment BReg by 1
Yes
No
If c=0
Program
After Execution
A B C D* E* F H L
00 00 00 00 00 44 81 04
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 0 1 0
Practical No. 7
Write a program that divides two 1 byte hex numbers stored in consecutive
memory locations starting from 8030. Store the quotient and remainder in next
consecutive memory locations
Program Steps
1. Start
2. Initialize A & B register to zero.
3. Fetch data from memory location 8030. For this, initialize HL pointer to
8030.
4. Move memory variable M(dividend) into A reg.
5. Increment HL pointer by one. So it points to memory location 8031.
6. Compare memory variable M with Accumulator.
7. If Acc < M then
a. Goto step 11
8. Subtract divisor from dividend (A=A-M).
9. Increment quotient i.e B Reg by one.
10. Goto step 6
11. Increment HL by one.
12. Store quotient at memory location pointed by HL i.e 8032.
13. Increment HL by one.
14. Store remainder at memory location pointed by HL i.e 8033.
15. Stop
Flowchart: Start
Initialize HL as pointer to
8030
Increment HL by one
Increment HL by one
Store remainder at memory
location pointed by HL
Yes
If A < M
Stop
No
Subtract divisor from
dividend (A=A-M)
Opcode Operand
After Execution
General Registers
* - Registers not used in program
A B C D* E* F H L
00 00 00 00 00 81 80 33
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
1 0 0 0 1
Practical No.8
Program Steps
1. Start
2. Initialize C Reg. to length of block.
3. Fetch data from memory location 8030. For this, initialize HL pointer to
8030.
4. Move memory variable M into D reg (greatest No.).
5. Move memory variable M into E reg (smallest No.).
6. Decrement C Reg(Length) by one
7. Increment HL by one. So data can be fetched by memory variable M.
8. Store memory variable M into Accumulator.
9. Compare Accumulator with D Reg
10. If D>A then
a. Goto step 12
11. Move Accumulator into D Reg.
12. If E<A then
a. Goto step 14
13. Move Accumulator into E Reg.
14. Decrement C Reg(Length) by one
15. If C is not zero then
a. Goto step 7
16. Increment HL by one
17. Store D Reg. contents at memory location pointed by HL.
18. Increment HL by one
19. Store E Reg. contents at memory location pointed by HL.
20. Stop
Flowchart Start
No
Move M into D If C=0
Move M into E Yes
Increment HL by one
Increment HL by one
Increment HL by one
Yes
If D>A
Store E Reg into memory
No location pointed by HL
Move Accumulator into D
Reg.
Stop
Yes
If E<A
No
Move Accumulator into E
Reg.
Program
Opcode Operand
8012 80
8017 80
After Execution
General Registers
- Registers not used in program
A B* C D E F H L
18 00 00 85 01 54 80 3C
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0
Program No.9
Program Steps
1. Start
2. Set length of block to C Reg.
3. Set 0 to D Reg, E Reg.
4. Fetch data from memory location 8060. For this, initialize HL pointer to
8060.
5. Move memory variable M into A reg.
6. Rotate contents of A to right by 1 as well as in carry flag.
7. If carry flag is not set then
a. goto step 10
8. Increment E Reg.(Even counter) by one.
9. Goto step 11
10. Increment D reg. (Odd counter) by one.
11. Increment HL by one.
12. Decrement C Reg. (Length) by one.
13. If C is not zero then
a. Goto step 5
14. Store E Reg. contents to memory location pointed by HL.
15. Increment HL by one.
16. Store D Reg. contents to memory location pointed by HL.
17. Stop
Flowchart
Start
Yes
Initialize HL as pointer to
Store E reg. to memory
8060
location pointed by HL
Yes Stop
If cy=0
No
Increment HL by one
Program
After Execution
General Registers
* - Registers not used in program
A B* C D E F H L
1D FF 00 06 07 55 80 6E
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 1
Practical No.10
Write a program that subtracts the number stored in 8030 H from the number
stored in 8031 H. Store the absolute difference in memory location 8032 H as
result.
Program Steps
1. Start
2. Fetch data from memory location 8030. For this, initialize HL pointer to
8030.
3. Move memory variable M (subtractor) into B reg.
4. Increment HL pointer by one. So it points to memory location 8031.
5. Move memory variable M into A Reg.
6. Subtract Accumulator from B Reg. (A=A-B)
7. If Acc Result is positive then
a. Goto step 10
8. Take 1’s complement of Accumulator result.
9. Add 1 to get 2’s complement
10. Increment HL by one.
11. Store Accumulator result at memory location pointed by HL i.e
8032.
12. Stop
Flowchart
Start
Initialize HL as pointer to
8030
Subtract Accumulator
from B Reg.
Yes
If result is
positive
No
Take 1’s complement of
Accumulator
Add 1 to accumulator
Increment HL by one
Stop
Program
General Registers
* - Registers not used in program
A B C* D* E* F H L
01 06 00 00 00 00 80 32
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 0 0 0 0
Practical No.11
Write a program to find first occurrence of AB H data. The length of the block
is stored at 807F H. The data is stored from memory location 8080 H. Store
the address of this occurrence in HL pair. If data is not found, store FFFF H in
HL pair.
Program Steps
1. Start
2. Fetch data from memory location 807F. For this, initialize HL pointer to
807F.
3. Move memory variable M (length of block) into C reg.
4. Move AB data in accumulator.
5. Increment HL by one, so data can be fetched by memory variable M.
6. Compare memory variable M with accumulator.
7. If zero flag set then
a. Goto step 11
8. Decrement counter C reg. by one.
9. If C reg is not zero then
a. Goto step 5
10. Initialize HL pair with value FFFF if no data available.
11. Stop
Flowchart
Start
Initialize HL as pointer to
807F
Move AB data in
Accumulator
Increment HL by one
No
Compare M
with Acc.
Yes
Decrement counter C reg.
by one
If counter =0
Stop
Program
After Execution
A B* C D* E* F H L
AB 00 04 00 00 54 80 81
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0
Practical No.12
Write a program to find how many times data AD H appears in memory block
starting from 8030H and length of block is at 802F H. store the count 9000 H.
Program Steps
1. Start
2. Initialize C reg. to zero.
3. Store AD data in Accumulator.
4. Fetch data from memory location 802F. For this, initialize HL pointer to
802F.
5. Move M contents in B reg.
6. Increment HL by one, so data can be fetched by memory variable M.
7. Compare memory variable M with accumulator.
8. If zero flag not set then
a. Goto step 9
9. Increment counter C reg. by one.
10. Increment HL by one.
11. Decrement B reg. by one.
12. If B reg. is not zero then
a. Goto step 6
13. Move C reg. to accumulator.
14. Store accumulator result in memory location 9000.
15. Stop
Flowchart
Start
Set C reg. to 0
Move AD data in
accumulator
Initialize HL pointer to
807F to get length of block
Increment HL by one
If zero
No flag set Move C reg. to
Yes Accumulator
No Yes
If B =0
Program
After Execution
General Registers
* - Registers not used in program
A B C D* E* F H L
02 00 02 00 00 54 80 34
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0
Program No.13
Program Steps
1. Start
2. Initialize C reg. to 08.
3. Set B reg. to 0
4. Fetch data from memory location 8400 in accumulator
5. Shift Least significant bit in carry.
6. If carry is one then
a. Goto step 8
7. Increment B reg. by one
8. Decrement C reg. by one
9. If C is not zero 0then
a. Goto step 5
10. Move B reg. contents into A reg.
11. Store accumulator result in memory location 8500
12. Stop
Flowchart
Start
Yes
If
Carry=1
No
Yes No
If count Store result in memory
is not location 8500
zero
Stop
Program
After Execution
General Registers
* - Registers not used in program
A B C D* E* F H* L*
03 03 00 00 00 54 FF FF
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0
Practical No.14
Program Steps
1. Start
2. Move length of block to C Reg. as counter
3. Fetch data from memory location 8060. For this, initialize HL pointer to
8060.
4. Fetch data from memory location 8100. For this, initialize DE pointer to
8100.
5. Load accumulator data with data in memory pointed by DE pair.
6. Copy data of memory pointed by HL pair in B Reg.
7. Copy Accumulator data to M (memory pointed by HL)
8. Copy B reg. data to Accumulator.
9. Store Accumulator Data to memory pointed by DE pair.
10. Increment HL by one
11. Increment DE by one
12. Decrement C reg. (counter) by one
13. If counter is not zero then
a. Goto step 5
14. Stop
Flowchart
Start
Increment HL by one
After Execution
A B C D E F H L
11 11 00 81 0B 54 80 6B
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 0 1 0
Practical No.15
A block of data is stored in memory location starting from 8080H and 808BH.
WAP to transfer the data in reverse order to memory location from 8180H
Program Steps
1. Start
2. Move length of block to C Reg. as counter
3. Fetch data from memory location 8080. For this, initialize HL pointer to
8080.
4. Fetch data from memory location 8180. For this, initialize DE pointer to
8180.
5. Move Memory variable M to accumulator.
6. Store accumulator data to memory pointed by DE.
7. Decrement HL by one
8. Increment DE by one
9. Decrement C reg. (counter) by one
10. If counter is not zero then
a. Goto step 5
11. Stop
Flowchart
Start
Decrement HL by one
Increment DE by one
Program
Before Execution
After Execution
A B C D E F H L
00 01 00 80 8C 54 81 7F
Flag Register
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
0 1 1 1 0