Cs 2 Practicals

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

List of Practical

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

Initialize HL pair to 8030.

Move data of 8030 to A


reg.

Increment value of HL pair


by one.

Add accumulator data with


value at HL

Store Accumulator result


into 8032

Stop
Program

Address Label Mnemonics Hexcode Comment

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

Details after program execution

Before Execution
Memory Location Data
8030 5
8031 6
8032 00

After Execution

Memory Location Data


8030 5
8031 6
8032 11
General Purpose Register
*- Indicates register not used in the program.

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

Move first number in A


Reg.

Increment HL by one

Decimal Adjust
Accumulator

Yes
If cy=0 Store the accumulator result
in memory location 8032

No Move C Reg. data to


Accumulator
Increment C Reg. by one

Store the accumulator


result in memory location
8033
Stop
Program

Address Label Mnemonics Hexcode Comment


Opcode Operand
8000 START LXI H,8030 21 Initialize HL as a memory
pointer
8001 30 Lower address byte
8002 80 Upper address byte
8003 MVI C,00H 0E Initialize C Reg. to zero
8004 00
8005 MOV A,M 7E Move first number in A
reg.
8006 INX H 23 Increment HL pointer by
one
8007 ADD M 86 Add accumulator data
with HL pointer data
8008 DAA 27 Decimal adjust
accumulator
8009 JNC 800D D2 If carry not generated
jump to 800D
800A 0D Lower address byte
800B 80 Upper address byte
800C INR C 0C Increment C reg. by one
800D STA 8032H 32 Store the result in
memory location 8032
800E 0D Lower address byte
800F 80 Upper address byte
8010 MOV A,C 79 Move C reg. data to
accumulator
8011 STA 8033H 32 Store carry in memory
location 8033
8012 33 Lower address byte
8013 80 Upper address byte
8014 RST1 CF Stop program execution
Details after program execution
Before Execution

Memory Locations Data


8030 09
8031 06
8032 00

After Execution

Memory Locations Data


8030 09
8031 06
8032 15

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

Clear A&B Reg to zero Increment HL by one

Store accumulator result in


Initialize HL as pointer to
memory location pointed by HL
8030

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

Add M variable into


Accumulator

Yes Decrement C Reg


If cy=0
by 1

No
Increment BReg by 1 If c=0
No

Yes
Program

Address Label Mnemonic HexCode Comment

Opcode Operand

8000 START XRA A AF Clear A reg to


zero
8001 MOV B,A 47 Initialize B reg to
zero
8002 LXI H,8030 21 Initialize HL reg
as memory
pointer
8003 30 Lower Address
Byte
8004 80 Higher Order
Byte
8005 MOV C,M 4E Move length in C
reg.
8006 INX H 23 Increment HL
pointer by 1
8007 L1 ADD M 86 Add memory
contents to
Accumulator
8008 JNC 800C D2 If cy=0 then jump
to label P1
8009 0C Lower Address
Byte
800A 80 Higher Address
Byte
800B INR B 04 Increment B Reg
by 1
800C P1 DCR C 0D Decrement C by 1

800D JNZ 8007 C2 If counter c is not


zero then jump to
label L1
800E 07 Lower Address
Byte
800F 80 Higher Address
Byte
8010 INX H 23 Increment HL
pointer by 1
8011 MOV M,A 77 Move result of
Acc to memory
location pointed
by HL
8012 INX H 23 Increment HL
pointer by 1
8013 MOV M,B 70 Move carry from
Reg B to memory
location pointed
by HL
8014 STOP RST CF Stop program
execution
Practical No. 6

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

Clear A&B Reg to zero


Store accumulator result in memory
location poinerd by HL i.e 8060

Initialize HL as pointer to 80FF


Move B Reg to A Reg.
Add 0 to A Reg

Move Length of block in C


Reg
Decimal Adjust Accumulator

Increment HL by one
Store accumulator result in memory
location poinerd by HL i.e 8061

Decimal Adjust Accumulator


Stop
Yes

If cy=0 Decrement C Reg by 1

No
Increment BReg by 1

Yes
No
If c=0
Program

Address Label Mnemonics Hexcode Comment


Opcode Operand
8000 START XRA A AF Set A Reg. to 0
8001 MOV B,A 47 Set B Reg to 0
8002 LXI H,80FF 21 Initialize HL to memory
address 80FF H
8003 FF Lower Address Byte
8004 80 Upper Address Byte
8005 MOV C,M 4E Move Memory contents
to C Reg.
8006 S1 INX H 23 Increment HL by 1
8007 ADD M 86 Add Accumulator
contents with M contents
8008 DAA 27 Decimal Adjust
Accumulator
8009 JNC 800D D2 If carry flag not set then
goto label S2
800A 0D Lower Address Byte
800B 80 Upper Address Byte
800C INR B 04 Increment B Reg. by 1
800D S2 DCR C 0D Decrement C (Length)
Reg by 1
800E JNZ 8006 C2 If counter (zero flag) not
set, then goto label S1
800F 06 Lower Address Byte
8010 80 Upper Address Byte
8011 STA 8060 32 Store Accumulator Data
at memory location 8060
H
8012 60 Lower Address Byte
8013 80 Upper Address Byte
8014 MOV A,B 78 Move B Reg to A Reg
8015 ADI 00 C6 Add 0 to Accumulator
8016 00
8017 DAA 27 Decimal Adjust
Accumulator
8018 STA 8061 32 Store Accumulator data at
memory location 8061 H
8019 61 Lower Address Byte
801A 80 Upper Address Byte
801B STOP RST1 CF Stop Execution

Details after program execution


Before Execution

Memory Locations Data


80FF 05
8100 02
8101 03
8102 05
8103 06
8104 07

After Execution

Memory Locations Data


80FF 05
8100 02
8101 03
8102 05
8103 06
8104 07
8060 23
8061 00
General Registers
* - Registers not used in program

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

Clear A&B Reg to zero

Initialize HL as pointer to
8030
Increment HL by one

Move dividend in A Reg


Store quotient at memory
location pointed by HL

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)

Increment B reg. (quotient)


by 1
Program

Address Label Mnemonic HexCode Comment

Opcode Operand

8000 START XRA A AF Clear A reg to zero


8001 MOV B,A 47 Initialize B reg to
zero
8002 LXI H,8030 21 Initialize HL reg as
memory pointer
8003 30 Lower Address
Byte
8004 80 Higher Order Byte

8005 MOV A,M 7E Move dividend in


A Reg
8006 INX H 23 Increment HL
pointer by 1
8007 PP CMP M BE Compare to check
dividend is greater
than divisior
8008 JC 8010 DA If A<M the goto
label VP

8009 10 Lower Address


Byte
800A 80 Higher Address
Byte
800B SUB M 96 Subtract divisior
from dividend
800C INR B 04 Increment quotient
by 1
800D JMP 8007 C3 Jump
unconditionally to
label PP
800E 07 Lower Address
Byte
800F 80 Higher Address
Byte
8010 VP INX H 23 Increment HL
pointer by 1
8011 MOV M,B 70 Store quotient at
8032
8012 INX H 23 Increment HL
pointer by 1
8013 MOV M,A 70 Store reminder at
8033H
8014 STOP RST1 CF Stop program
exeuction
Details after program execution
Before Execution

Memory Locations Data


8030 0D
8031 03

After Execution

Memory Locations Data


8030 0D
8031 03
8032 04
8033 01

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

A block of data is stored in memory locations from 8030H to 803AH. Write a


program to find smallest as well as greatest number from this block using
linear search. Store the result immediately after the end of block.

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

Set C Reg to length

Initialize HL as pointer to Decrement C Reg. by one


8030

No
Move M into D If C=0
Move M into E Yes

Increment HL by one
Increment HL by one

Store D Reg into memory


location pointed by HL
Store M into Accumulator

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

Address Label Mnemonic HexCode Comment

Opcode Operand

8000 START MVI C,0B 0E Store length of


block in C Reg
8001 0B

8002 LXI H,8030 21 Initialize HL as a


memory pointer
8003 30 Lower Address
Byte
8004 80 Upper Address
Byte
8005 MOV D,M 56 Assume D
contents are
greatest
8006 MOV E,M 5E Assume E contents
are smallest
8007 DCR C 0D Decrement Length
by 1
8008 VP INX H 23 Increment HL by 1

8009 MOV A,M 7E Store next memory


contents in A
800A CMP D BA Compare
Accumulator with
D
800B JC 800F DA If D>A, then goto
label SML
800C 0F Lower Address
Byte
800D 80 Upper Address
Byte
800E MOV D,A 57 Move Acc (Greatst
) in D
800F SML CMP E BB Compare
Accumulator with
E
8010 JNC 8014 D2 If E<A, then goto
label NXT
8011 14

8012 80

8013 MOV E,A 5F Move Acc


(Smallest) in E
8014 NXT DCR C 0D Decrement length
by 1
8015 JNZ 8008 C2 If flag z is not 0
then goto label VP
8016 08

8017 80

8018 INX H 23 Increment HL by 1

8019 MOV M,D 72 Store D contents


(Greatst) in
memory
801A INX H 23 Increment HL by 1
801B MOV M,E 73 Store E contents
(Smallest) in
memory
801C STOP RST1 CF Stop the program
execution

Details after program execution


Before Execution

Memory Location Data


8030 06
8031 56
8032 01
8033 59
8034 14
8035 55
8036 10
8037 85
8038 05
8039 12
803A 07

After Execution

Memory Location Data


8030 06
8031 56
8032 01
8033 59
8034 14
8035 55
8036 10
8037 85
8038 05
8039 12
803A 18
803B 85 (Largest No.)
803C 01 (Smallest No.)

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

A block of data is stored in memory locations from 8060H to 806CH. Write a


program to find ODD as well as EVEN numbers from this block. Store the
result immediately after the end of block.

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

Set C reg. to length Decrement Counter C Reg. by


one

Initialize D reg. with 0


Initialize E reg. with 0 No If C=0

Yes
Initialize HL as pointer to
Store E reg. to memory
8060
location pointed by HL

Store M into Accumulator Increment HL by one

Store D Reg to memory


Rotate contents of A to right location pointed by HL
by 1 as well as in carry flag

Yes Stop
If cy=0

No

Increment E Reg. by one

Increment D Reg. by one

Increment HL by one
Program

Address Label Mnemonics HexCode Comment


Opcode Operand
8000 START MVI C,0D 0E Store length of block in
C reg
8001 0D
8002 MVI D,00 16 Set D Reg to 0
8003 00
8004 MOV E,D 5A Set E Reg to 0
8005 LXI H,8060 23 Initialize HL pointer
8006 60 Lower Address Byte
8007 80 Upper Address Byte
8008 VP MOV A,M 7E Load ACC with M
8009 RRC 0F Rotate contents of A to
right by 1 as well as in
carry flag
800A JNC 8011 D2 If carry flag is not set
then goto label EVEN
800B 11
800C 80
800D INR E 1C Increment even counter
by 1
800E JMP 8012 C3 Jump unconditionally
800F 12
8010 80
8011 EVEN INR D 14 Increment D by 1
8012 NXT INX H 23 Increment HL by 1
8013 DCR C 0D Decrement C by 1
8014 JNZ 8008 C2 If counter not zero then
goto label VP
8015 08
8016 80
8017 MOV M,D 72 Move Even counter to
memory
8018 INX H 23 Increment HL by 1
8019 MOV M,E 73 Move Odd counter to
memory
801A STOP RST1 CF Stop Exeuction

Details after program execution


Before Execution

Memory Locations Data


8060 14
8061 12
8062 19
8063 23
8064 50
8065 05
8066 01
8067 03
8068 24
8069 10
806A 06
806B 29
806C 11

After Execution

Memory Locations Data


8060 14
8061 12
8062 19
8063 23
8064 50
8065 05
8066 01
8067 03
8068 24
8069 10
806A 06
806B 29
806C 1D
806D 06 (Total Even Nos.)
806E 07 (Total Odd Nos.)

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

Store M into Accumulator

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

Move Accumulator to memory


location pointed by HL

Stop
Program

Address Label Mnemonics Hex Comment


Code
Opcode Operand
8000 STAR LXI H,8030 21 Initialize HL as memory
T pointer to 8030H
8001 30
8002 80
8003 MOV B,M 46 Move subtractor in B Reg.
8004 INX H 23 Increment HL by 1
8005 MOV A,M 7E Move M contents to
Accumlator
8006 SUB B 90 Subtract A from B
8007 JP 800D F2 If result is positive goto
label VP
8008 0D
8009 80
800A CMA 2F Take 1’s complement of
Accumulator
800B ADI 01 C6 Add 1 to get 2’s
complement
800C 01
800D VP INX H 23 Increment HL by 1
800E MOV M,A 77 Move Accumulator
contents to Memory
800F STOP RST1 CF Stop Execution

Details after program execution


Before Execution

Memory Locations Data


8030 06
8031 0A
After Execution

Memory Locations Data


8030 06
8031 0A
8032 04

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 M contents into


C reg.

Move AB data in
Accumulator

Increment HL by one

No
Compare M
with Acc.

Yes
Decrement counter C reg.
by one

If counter =0

Initialize HL pair with value


FFFF if no data available

Stop
Program

Address Label Mnemonics HexCode Comment


Opcode Operand
8000 START LXI H,807F 21 Initialize HL pointer
to memory location
807F
8001 7F
8002 80
8003 MOV C,M 4E Move M contents to
C Reg.
8004 MVI A,AB 3E Move AB data in
Accumulator
8005 AB
8006 BACK INX H 23 Increment HL by 1
8007 CMP M BE Compare M contents
with Accumulator
8008 JZ 8012 CA If zero flag set, then
goto label STOP
8009 12
800A 80
800B DCR C 0D Decrement Counter
by 1
800C JNZ 8006 C2 If zero flag not set,
then goto label
BACK
800D 06
800E 80
800F LXI H,FFFF 21 Initialize HL pair
with value FFFF if
no data available
8010 FF
8011 FF
8012 STOP RST1 CF Stop Execution
Details after program execution
Before Execution

Memory Locations Data


807F 05
8080 21
8081 AB
8082 33
8083 AB
8084 BC

After Execution

Memory Locations Data


807F 05
8080 21
8081 AB
8082 33
8083 AB
8084 BC
General Registers
* - Registers not used in program

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

Move M(Length) in B reg.

Increment HL by one

Compare M with acc.

If zero
No flag set Move C reg. to
Yes Accumulator

Increment C reg. by one


Store Accumulator contents
in memory location 9000
Increment HL by one
Stop

Decrement B reg. by one

No Yes
If B =0
Program

Address Label Mnemonics HexCode Comment


Opcode Operand
8000 START MVI C,00 0E Set C Reg to 0
8001 00
8002 MVI A,AD 3E Store Data AD in
Accumulator
8003 AD
8004 LXI 802F 21 Initialize HL pointer
with 802F
8005 2F Lower Address Byte
8006 80 Upper Address Byte
8007 MOV B,M 46 Move M contents in B
reg.
8008 INX H 23 Increment HL pointer
to point next memory
location
8009 BACK CMP M BE Compare M contents
with Accumulator
800A JNZ 800E C2 If zero flag not set,
then goto label NEXT
800B 0E Lower Address Byte
800C 80 Upper Address Byte
800D INR C 0C Increment Counter by
2 1
800E NEXT INX H 23 Increment HL by 1
800F DCR B 05 Decrement B Reg by 1
8010 JNZ 8009 C2 If zero flag not set,
then goto Label
BACK
8011 09 Lower Address Byte
8012 80 Upper Address Byte
8013 MOV A,C 79 Move C Reg to
Accumulator
8014 STA 9000 32 Store Result (C Reg
Contents) in memory
location 9000 H
8015 00 Lower Address Byte
8016 90 Upper Address Byte
8017 STOP RST1 CF Stop Execution

Details after program execution


Before Execution

Memory Locations Data


802F 04
8030 12
8031 AD
8032 24
8033 AD

After Execution

Memory Locations Data


802F 04
8030 12
8031 AD
8032 24
9000 02

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

A 8 bit number is stored in memory location 8400H. Write an assembly


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

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

Set C reg. (counter) to 8

Set B reg.to 0 to store


count of items

Get the number in


accumulator

Shift LSB in carry

Yes
If
Carry=1

No

Increment B reg. by one

Decrement C reg. by one Get B reg. contents in


Accumulator

Yes No
If count Store result in memory
is not location 8500
zero

Stop
Program

Address Label Mnemonics HexCode Comment


Opcode Operand
8000 START MVI C,08 0E Set counter to 08H
8001 08
8002 MVI B,00 06 Set B Reg to 0 to store
count of zeros
8003 00
8004 LDA 8400 3A Get number in Acc.
8005 00
8006 84
8007 BACK RRC 0F Shift Least significant
bit in carry
8008 JC 800C DA If carry=1, then goto
label NEXT
8009 0C
800A 80
800B INR B 04 Increment B by 1
800C NEXT DCR C 0D Decrement C by 1
800D JNZ 8007 C2 If counter is not zero
then goto label BACK
800E 07
800F 80
8010 MOV A,B 78 Get B reg Contents in
Acc
8011 STA 8500 32 Store result (Acc .data)
in memory location
8500
8012 00
8013 85
8014 STOP RST1 CF Stop Execution
Details after program execution
Before Execution

Memory Locations Data


8400 75

After Execution

Memory Locations Data


8400 75
8500 03

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

A block of data is stored in memory locations from 8060 H to 806A H.


Another block of data having same length is stored in memory locations
starting from 8100 H. Write a program to exchange the contents of these two
blocks.

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

Move length to C reg.


Decrement C reg. by one
Initialize HL pointer to
memory location 8060
Yes
If C reg.
Initialize DE pointer to is not 0
memory location 8100
No

Load accumulator with data Stop


of memory pointed by DE

Copy data of memory


pointed by HL pair in B reg.

Copy Accumulator data to


memory pointed by HL

Copy B reg. data to


Accumulator

Store Accumulator Data to


memory pointed by DE pair.

Increment HL by one

Decrement DE. by one


Program

Address Label Mnemonics HexCode Comment


Opcode Operand
8000 START MVI C,0B 0E Move length of block
to C Reg. as counter.
8001 0B
8002 LXI H,8060 21 Initialize HL as a
pointer to memory
location 8060 H
8003 60 Lower Address Byte
8004 80 Upper Address Byte
8005 LXI D,8100H 21 Initialize DE as a
pointer to memory
location 8100 H
8006 00 Lower Address Byte
8007 81 Upper Address Byte
8008 LOOP LDAX D 1A Load accumulator data
with data in memory
pointed by DE pair.
8009 MOV B,M 46 Copy data of memory
pointed by HL pair in
B Reg.
800A MOV M,A 77 Copy Accumulator
data to M (memory
pointed by HL)
800B MOV A,B 78 Copy B Reg data to
Accumulator.
800C STAX D 12 Store Accumulator
Data to memory
pointed by DE pair.
800D INX H 23 Increment HL by 1
800E INX D 13 Increment DE by 1
800F DCR C 0D Decrement Counter by
1
8010 JNZ 8008 C2 If counter not zero then
goto label LOOP
8011 08 Lower Address Byte
8012 80 Upper Address Byte
8013 STOP RST1 CF Stop Execution.

Details after program execution


Before Execution

Memory Locations Data Memory Locations Data


8060 01 8100 20
8061 02 8101 21
8062 03 8102 22
8063 04 8103 23
8064 05 8104 24
8065 06 8105 25
8066 07 8106 26
8067 08 8107 27
8068 09 8108 28
8069 10 8109 29
806A 11 810A 30

After Execution

Memory Locations Data Memory Locations Data


8060 20 8100 01
8061 21 8101 02
8062 22 8102 03
8063 23 8103 04
8064 24 8104 05
8065 25 8105 06
8066 26 8106 07
8067 27 8107 08
8068 28 8108 09
8069 29 8109 10
806A 30 810A 11
General Registers
* - Registers not used in program

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

Move length to C reg.


Decrement C reg. by one
Initialize HL pointer to
memory location 808B
Yes
If C reg.
Initialize DE pointer to is not 0
memory location 8180
No

Move memory variable M Stop


into accumulator

Store accumulator data to


memory pointed by HL

Decrement HL by one

Increment DE by one
Program

Address Label Mnemonic/ HexCode Comment


Opcode Operand
8000 Start MVI C,0CH 06 Set counter to length of
block
8001 0C
8002 LXI H,808B 21 HL with data of 8080
8003 8B Lower Address Byte
8004 80 Upper Address Byte
8005 LXI D,8180 21 DE with contents of
8060
8006 80 Lower Address Byte
8007 81 Upper Address Byte
8008 UP MOV A,M 7E Move HL contents to
ACC
8009 STAX D 12 Store ACC to memory
pointer by DE
800A INX D 13 Increment DE by 1
800B DCX H 2B Decrement HL by 1
800C DCR C 0D Decrement C reg. or
counter by 1
800D JNZ 8008 C2 If C reg. is zero then
Jump to address 8008
08 Lower Address Byte
80 Upper Address Byte
800E STOP RST1 CF Stop Execution
Details after program execution

Before Execution

Memory Location Data


8080 00
8081 01
8082 02
8083 03
8084 04
8085 05
8086 06
8087 07
8088 08
8089 09
808A 10
808B 11

After Execution

Memory Location Data


8180 11
8181 10
8182 09
8183 08
8184 07
8185 06
8186 05
8187 04
8188 03
8189 02
818A 01
818B 00
General Registers
* - Registers not used in program

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

You might also like