0% found this document useful (0 votes)
16 views

Microprocessor Alp (Repaired)

The document describes programs for 8085 microprocessor to perform multi-byte hexadecimal and decimal addition and subtraction operations. It includes the flow charts and assembly language codes for: 1. Adding two 8-bit hexadecimal numbers stored in memory locations and storing the 16-bit sum. 2. Performing multi-byte hexadecimal addition by adding bytes from two memory blocks and storing the results in the first block. 3. Performing multi-byte decimal addition by adding bytes similar to hexadecimal addition but also performing decimal adjustment on the sum.

Uploaded by

smileyavi0923
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Microprocessor Alp (Repaired)

The document describes programs for 8085 microprocessor to perform multi-byte hexadecimal and decimal addition and subtraction operations. It includes the flow charts and assembly language codes for: 1. Adding two 8-bit hexadecimal numbers stored in memory locations and storing the 16-bit sum. 2. Performing multi-byte hexadecimal addition by adding bytes from two memory blocks and storing the results in the first block. 3. Performing multi-byte decimal addition by adding bytes similar to hexadecimal addition but also performing decimal adjustment on the sum.

Uploaded by

smileyavi0923
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

PRACTICAL-IV

MICROPROCESSOR 8085 AND MICROCONTROLLER 8051

Any 14 Experiments

Microprocessor 8085
1. Program for multibyte hexadecimal addition/subtraction
2. Program for multibyte decimal addition/subtraction. .
3. 1’s and 2’s complements in an array
4. Shift left and right 8 bit number by one bit.
5. Find largest / smallest numbers in a list.
6. Arrange in ascending /descending order.
7. Code conversion ASCII to Decimal and vice versa, Decimal to Binary and Binary to
Decimal.
8. Block of data transfer.
9. Rolling display.
10. Making an 8 bit DAC.
11. Making an 8-bit ADC (LED, RAM).
12. Wave form generation (sine, square, triangular) 8253.
13. Stepper motor interface.
14. Traffic light interface.
15. Digital clock.
16. Solid state relay interface.
17. Study of PPI 8255.

Microcontroller 8051
18. Program for addition and subtraction in 8 bits
19. Program for multiplication and division in 8 bits.
20. Sum of N numbers
21. Block of data transfer
22. Binary to decimal conversion vice –versa
Aim: Write an 8085 ALP to add two 8 –bits hexadecimal number in 4150H and 4151H
and store the sum 16-bits in 4152H and 4153H.

Flow chart:

Start

Get the address of the 1st number

Move 00H to register C

Clear the accumulator

Move the 1st number to Accumulator

Get the address of the 2nd number

Add the Accumulator content with the content of 4151H

Is
Yes No No
carr
y? Increment the C register by one

Get the address 4152H of the LSB of result

Move the content of Accumulator (LSB of the sum) to 4152H

Get the address of the MSB of sum

Move the content of Reg. C (MSB of the sum) to 4153H

Stop
Addition of Two 8-bits number

Sum-16 bits

Address Label Op-code Mnemonics Comments


4000 Start 21 50 41 LXI H 4150H Address of 1st number in HL pair
4003 0E MVI C 00 MSB of the sum in register C initial value =00
00

4005 AF XRA A Clear the accumulator


4006 7E MOV A, M 1ST number in Accumulator
4007 23 INX H Address of 2nd number in HL pair
4008 86 ADD M 1st number + 2nd number
4009 D2 0D 40 JNC AHEAD Is carry? no go to AHEAD
400C 0C INR C Yes increment C
400D AHEAD 23 INX H Increment the address 4152H
400E 77 MOV M, A LSB of the result in 4152H
400F 23 INX H Increment the address 4153H
4010 71 MOV M, C MSB of the result in 4153H
4011 76 HLT Terminate the program

Input 1 Output

Address Data Address Data

4150H 56H 4152H 70H (LSB)

4151H 1AH 4153H 00H (MSB)

Input 2 Output

Address Data Address Data

4150H 9BH 4152H 3EH (LSB)

4151H A3H 4153H 01H (MSB)


Program:

Address HEX Codes Labels Mnemonics Comments

4100 21, 00, 45 LXI H,4500H Point to get the count

4103 4E MOV C,M Get the count to C

4104 11, 01, 45 LXI D,4501H Point to first number

4107 21, 51, 45 LXI H,4551H Point to second number

410A 37 STC Set the carry flag

410B 3E, 99 LOOP MVI A,99H Load 99H into A

410D CE,00 ACI 00H Add 00H and Carry with A

410F 96 SUB M Subtract M from A

4110 EB XCHG Exchange DE and HL

4111 86 ADD M Add M to A

4112 27 DAA Decimal adjust

4113 77 MOV M,A Store A to memory

4114 EB XCHG Exchange DE and HL

4115 23 INX H Point to next location by HL

4116 13 INX D Point to next location by DE

4117 0D DCR C Decrease C by 1

4118 C2, 0B, 41 JNZ LOOP Jump to LOOP if Zis not = 0

411B 76 HLT Terminate the program


Output:

Address Data

4501 85

4502 69

4503 39

Input:

Address Data

4500 03

4501 73

4502 21

4503 67

4551 88

4552 51

4553 27
PROGRAM FOR MULTIBYTE HEXA DECIMAL ADDITION

Aim: Write an 8085 ALP for multi-byte Hexadecimal addition stored in memory
location 4151H (Starting address of the First multi-byte number) and 4251H (Starting
address of the second multi-byte number) and stores the result in the First multi–byte
number address.

Flow chart:
Start

Get i) byte count


ii) Byte of the 1st number
iii) Byte of the 2nd number
iv) carry =0

Add the byte of 1st and 2nd number with carry

Store Sum in memory where byte of 1st number was residing

Get next byte of 1st and 2nd numbers

Decrement the byte

No Yes
Is
count=0
?

Stop
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 50 41 LXI H 4150 Address of byte count in H L pair
4103 4E MOV C,M Byte count in register C
4104 23 INX H Address of the 1st byte of the 1st number
4105 11 51 42 LXI D,4251 Address of the 1st byte of the 2nd number
4108 AF XRA A Clear carry
4109 1A REPEAT LDAX,D get byte of 2nd number in accumulator
410A 8E ADC,M Byte of 2nd number+byte of 1st number +carry
410B 77 MOV M,A Store sum in memory addressed by H-L pair
410C 23 INX H Increment the address pointed by H-L pair
410D 13 INX D Increment the address pointed by D-E pair
410E 0D DCR C Decrement the count
410F C2 09 41 JNZ REPEAT Is count=0? No jump to REPEAT
4112 76 HLT Halt the program
PROGRAM FOR MULTIBYTE DECIMAL ADDITION
Aim: Write an 8085 ALP for multi-byte Decimal addition stored in memory location
4151H (Starting address of the First multi-byte number) and 4251H (Starting address of
the second multi-byte number) and stores the result in the First multi–byte number
address.

Flow chart:
Start

Get i) byte count


ii) Byte of the 1st number
iii) Byte of the 2nd number
iv) carry =0

Add the byte of 1st and 2nd number with carry

Decimal adjust accumulator to get the sum in decimal form

Store Sum in memory where byte of 1st number was residing

Get next byte of 1st and 2nd numbers

Decrement the byte

No Yes
Is
count=0
?

Stop
PROGRAM FOR MULTIBYTE DECIMAL ADDITION
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 50 41 LXI H 4150 Address of byte count in H L pair
4103 4E MOV C,M Byte count in register C
4104 23 INX H Address of the 1st byte of the 1st number
4105 11 51 42 LXI D,4251 Address of the 1st byte of the 2nd number
4108 AF XRA A Clear carry
4109 1A REPEAT LDAX,D get byte of 2nd number in accumulator
410A 8E ADC,M Byte of 2nd number+byte of 1st number +carry
410B 27 DAA Decimal adjust accumulator
410c 77 MOV M,A Store sum in memory addressed by H-L pair
410D 23 INX H Increment the address pointed by H-L pair
410E 13 INX D Increment the address pointed by D-E pair
410F 0D DCR C Decrement the count
4110 C2 09 41 JNZ REPEAT Is count=0? No jump to REPEAT
4113 76 HLT Halt the program
PROGRAM FOR MULTIBYTE HEXA DECIMAL SUBTRACTION
Aim: Write an 8085 ALP for multi-byte Hexadecimal subtraction stored in memory
location 4151H (Starting address of the First multi-byte number) and 4251H (Starting
address of the second multi-byte number) and stores the result in the First multi–byte
number address.

Flow chart:

Start

Get i) byte count


ii) Byte of the 1st number
iii) Byte of the 2nd number
iv) Carry =0

Subtract theobyte of 2nd number from 1st number with borrow

Store difference in memory where byte of 1st number was


residing

Get next byte of 1st and 2nd numbers

Decrement the byte

No Yes
Is
count
=0?

Stop
PROGRAM FOR MULTIBYTE HEXA DECIMAL SUBTRACTION
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 50 41 LXI H 4150 Address of byte count in H L pair
4103 4E MOV C,M Byte count in register C
4104 23 INX H Address of the 1st byte of the 1st number
4105 11 51 42 LXI D,4251 Address of the 1st byte of the 2nd number
4108 AF XRA A Clear accumulator
4109 1A REPEAT LDAX,D get byte of 2nd number in accumulator
Subtract Byte of 2nd number from byte of 1st number with
410A 9E SBB,M borrow
410B 77 MOV M,A Store difference in memory addressed by H-L pair
410C 23 INX H Increment the address pointed by H-L pair
410D 13 INX D Increment the address pointed by D-E pair
410E 0D DCR C Decrement the count
410F C2 09 41 JNZ REPEAT Is count=0? No jump to REPEAT
4112 76 HLT Halt the program

Input:
PROGRAM FOR SUM OF N NUMBERS
Aim:
Write an 8085 ALP program for sum of a series of 8-bits number and store the result in
XX50H (Hexa-decimal)
Flow- Chart:

Star
t
INTIALISE H-L PAIR

COUNT VALUE IN REG. C


LSB OF SUM= 00
MSB OF SUM =00

INCREMENT H-L PAIR TO GET NEXT NUMBER

SUM=PREVIOUS SUM+NEXT NUMBER

NO
IS
CARRY?

YES

MSB OF SUM= PREVIOUS VALUE


+1

NO
Is
count=0
?
YES

STORE LSB AND MSB OF SUM

Stop
SUM OF A SERIES OF 8-BITS NUMBERS (HEXA DECIMAL)
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 4E MOV C,M Count in Register C
4104 3E 00 MVI A 00H LSB of the sum=00
4106 47 MOV B,A MSB of the sum = 00
4107 23 LOOP INX H Address of next data in H-L pair
4108 86 ADD M Previous sum + next number
4109 D2 0D 41 JNC AHEAD Is carry? No, go to AHEAD
410C 04 INR B Yes add carry to MSBs of sum
410D 0D AHEAD DCR C Decrement count
410E C2 07 41 JNZ LOOP Is count =0? No, jump to LOOP
4111 23 INX H Get the address to store LSB of sum
4112 77 MOV M,A Store the LSB of sum
4113 23 INX H Get the address to store MSB of sum
4114 70 MOV M,B Store the MSB of sum
4115 76 HLT Terminate the program
Aim:
Write an 8085 ALP program for sum of a series of 8-bits number and store the result in
XX50H (Hexa-decimal)
Flow- Chart:

Star
t

INTIALISE H-L PAIR

COUNT VALUE IN REG. C


LSB OF SUM= 00
MSB OF SUM =00

INCREMENT H-L PAIR TO GET NEXT NUMBER

SUM=PREVIOUS SUM+NEXT NUMBER

DECIMAL ADJUST ACCUMULATOR

NO
IS
CARRY?

YES
MSB OF SUM =PREVIOUS VALUE +1

Is
NO count=0
?

YES

STORE LSB AND MSB OF SUM

Stop
Sum of series of 8 –bits Decimal numbers

SUM OF A SERIES OF 8-BITS NUMBERS (DECIMAL)


ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 4E MOV C,M Count in Register C
4104 3E 00 MVI A 00H LSB of the sum=00
4106 47 MOV B,A MSB of the sum = 00
4107 23 LOOP INX H Address of next data in H-L pair
4108 86 ADD M Previous sum + next number
4109 27 DAA Decimal adjust accumulator
410A D2 0E 41 JNC AHEAD Is carry? No, go to AHEAD
410D 04 INR B Yes add carry to MSBs of sum
410E 0D AHEAD DCR C Decrement count
410F C2 07 41 JNZ LOOP Is count =0? No, jump to LOOP
4112 23 INX H Get the address to store LSB of sum
4113 77 MOV M,A Store the LSB of sum
4114 23 INX H Get the address to store MSB of sum
4115 70 MOV M,B Store the MSB of sum
4116 76 HLT Terminate the program
1’S COMPLEMENT OF NUMBERS IN AN ARRAY

AIM:
Write an 8085 ALP to find the 1’s complement of numbers in an array.

FLOW –CHART;

Start

INITIALISE H-L PAIR &DE PAIR

LOAD THE ACCUMULATOR ADDRESSED BY DE PAIR

GET THE oCOMPLEMENT OF THE ACCUMULATOR CONTENT

MOVE THE ACCUMULATOR CONTENT TO ADDRESS GIVEN BY H-L PAIR

INCREMENT H-L AND D-E PAIR

DECREMENT THE REG.C

No Yes
Is
count
=0?

Stop
1’S COMPLEMENT OF NUMBERS IN AN ARRAY
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 4E MOV C,M Count in Register C
4104 23 INX H Get the address where the result is stored
4105 11 51 42 LXI D 4251 Get the address of the number
4108 1A LOOP LDAX D Get the data to accumulator addressed by DE pair
4109 2F CMA 1’s complement of the number
410A 77 MOV M,A Store the result addressed by HL pair
410B 23 INX H Get the next address to store the result
410C 13 INX D Get the address of the 2nd number
410D 0D DCR C Decrement count
410E C2 07 41 JNZ LOOP Is count =0? No, jump to LOOP
4111 76 HLT Terminate the program
2’S COMPLEMENT OF NUMBERS IN AN ARRAY

AIM:
Write an 8085 ALP to find the 2’s complement of numbers in an array.

FLOW –CHART;

Start

INITIALISE H-L PAIR &DE PAIR

LOAD THE ACCUMULATOR ADDRESSED BY DE PAIR

GET THE COMPLEMENT OF THE ACCUMULATOR CONTENT

ADD 1 TO THE ACCUMULATOR

MOVE THE ACCUMULATOR CONTENT TO ADDRESS GIVEN BY H-L PAIR

INCREMENT H-L AND D-E PAIR

DECREMENT THE REG.C

No Yes
Is
count
=0?

Stop
2’S COMPLEMENT OF NUMBERS IN AN ARRAY
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 4E MOV C,M Count in Register C
4104 23 INX H Get the address where the result is stored
4105 11 51 42 LXI D 4251 Get the address of the number
4108 1A LOOP LDAX D Get the data to accumulator addressed by DE pair
4109 2F CMA 1’s complement of the number
410A 3C INR A Add 1 to the accumulator
410B 77 MOV M,A Store the result in the memory addressed by HL pair
410C 23 INX H Get the next address to store the result
410D 13 INX D Get the address of the 2nd number
410E 0D DCR C Decrement count
410F C2 08 41 JNZ LOOP Is count =0? No, jump to LOOP
4112 76 HLT Terminate the program
LARGEST AND SMALLEST NUMBER FROM AN ARRAY

AIM:
Write an 8085 ALP to find the largest number from an array.

FLOW-CHART: (Largest)

START

INITIALISE HL PAIR

GET THE COUNT IN THE REG. C

GET THE FIRST NUMBER IN THE ACCUMULATOR

YES
Is number in
Acc. A > next
number
NO
GET THE LARGER NUMBER IN ACCUMULATOR

DECREMENT COUNT

NO IS
COUNT
=0?

YES
STORE RESULT

STOP
LARGEST NUMBER FROM AN ARRAY
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 4E MOV C,M Count in Register C
4104 23 INX H Address of the first number in HL pair
4105 7E MOV A,M 1st number in accumulator
4106 0D DCR C Get the address of the number
4107 23 LOOP INX H Get the data to accumulator addressed by DE pair
4108 BE CMP M 1’s complement of the number
4109 D2 0D 41 JNC AHEAD Add 1 to the accumulator
410C 7E MOV A,M Store the result in the memory addressed by HL pair
410D 0D AHEAD DCR C Decrement count
410E C2 07 41 JNZ LOOP Is count =0? No, jump to LOOP
4111 32 50 42 STA 4250 Store the largest number in 4250H
4114 76 HLT Terminate the program
FLOW-CHART: (Smallest)

START

INITIALISE HL PAIR

GET THE COUNT IN THE REG. C

GET THE FIRST NUMBER IN THE ACCUMULATOR

YES
Is number in
Acc. A < next
number
NO
GET THE LARGER NUMBER IN ACCUMULATOR

DECREMENT COUNT

NO IS
COUNT
=0?

YES
STORE RESULT

STOP
SMALLEST NUMBER FROM AN ARRAY
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 4E MOV C,M Count in Register C
4104 23 INX H Address of the first number in HL pair
4105 7E MOV A,M 1st number in accumulator
4106 0D DCR C Get the address of the number
4107 23 LOOP INX H Get the data to accumulator addressed by DE pair
4108 BE CMP M 1’s complement of the number
4109 D2 0D 41 JC AHEAD Add 1 to the accumulator
410C 7E MOV A,M Store the result in the memory addressed by HL pair
410D 0D AHEAD DCR C Decrement count
410E C2 07 41 JNZ LOOP Is count =0? No, jump to LOOP
4111 32 50 42 STA 4250 Store the largest number in 4250H
4114 76 HLT Terminate the program
Code Conversion

ASCII to Decimal

Aim:

To convert the given ASCII number value to its decimal equivalent value.

Flow chart:

STAR
T

GET ASCII DATA

DATA=DATA-30H

YES NO
IS
DATA
>09H

RESULT=FFH RESULT=DATA

STOP
ASCII TO DECIMAL
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 7E MOV A,M Data is in Reg. A (Accumulator)
4104 DE 30 SUI 30 Subtract 30 from accumulator
4106 FE 0A CPI 0A Compare the accumulator content with 0A
4108 DA 0D 41 JC LOOP If A<0A store the result
410B 3E FF MVI A, FF No make the Result = FF
410D 23 LOOP INX H Memory address is incremented by 1
410E 77 MOVM,A Accumulator content is in 4201H
410F 76 HLT Halt
ASCII to Hexa- Decimal

Aim:

To convert the given ASCII number value to its Hexa-decimal equivalent value.

Flow chart:

STAR
T

GET ASCII DATA

DATA=DATA-30H

NO YES
IS
DATA
<0AH

Subtract 07H from Acc. A

RESULT=Accumulator content is in 4201

STOP
ASCII TO HEXA-DECIMAL
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 7E MOV A,M Data is in Reg. A (Accumulator)
4104 DE 30 SUI 30 Subtract 30 from accumulator
4106 FE 0A CPI 0A Compare the accumulator content with 0A
4108 DA 0D 41 JC LOOP If A<0A store the result
410B D6 07 SUI, 07 Subtract 07 from Accumulator
410D 23 LOOP INX H Memory address is incremented by 1
410E 77 MOVM,A Accumulator content is in 4201H
410F 76 HLT Halt
Hexa- Decimal to ASCII

Aim:

To convert the given Hexa-decimal number to ASCII value.

Flow chart:

STAR
T

Get Hexa-Decimal value in Accumulator


DATA

Compare Accumulator content with 0A

YES NO
IS
DATA
<0AH
Add 07 with Acc. A

Add 30 with Acc. A

RESULT=Accumulator content is in 4201

STOP
HEXA-DECIMAL TO ASCII
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 7E MOV A,M Data is in Reg. A (Accumulator)
4104 FE 0A CPI 0A Compare the accumulator content with 0A
4108 DA 0D 41 JC LOOP If A<0A store the result
410B C6 07 ADI, 07 Subtract 07 from Accumulator
410D C6 30 LOOP ADI 30 Memory address is incremented by 1
23 INX H memory address is increased by 1 to store result
410E 77 MOVM,A Accumulator content is in 4201H
410F 76 HLT Halt
Decimal to ASCII

Aim:

To convert the given Decimal number value to its ASCII equivalent value.

Flow chart:

STAR
T

GET DATA IN ACCUMULATOR

Compare 0A with Accumulator content

YES IS NO
Accumulator
<0AH

Move FF H to Accumulator
Add 30H to Accumulator A

RESULT=Accumulator content is in 4201

STOP
Decimal to ASCII
ADDRESS OPCODE LABEL MNEMONICS COMMENT
4100 21 00 42 LXI H 4200H Address of the count in H-L pair
4103 7E MOV A,M Data is in Reg. A (Accumulator)
4104 FE 0A CPI 0A Subtract 30 from accumulator
4106 DA 0D 41 JC LOOP If A<0A store the result
4109 3E FF MVI A FF Move FF to Accumulator
410B C3 10 41 JMP L2 Jump to the instruction labeled as L2
410E C6 30 LOOP ADI, 30H Subtract 07 from Accumulator
4110 23 L2 INX H Memory address is incremented by 1
4111 77 MOVM,A Accumulator content is in 4201H
4112 76 HLT Halt

Algorithm for descending order

1. Initialize HL pair as memory pointer


2. Get the count at 4150 into C - register
3. Copy it in D - register (for bubble sort (N-1) times required)
4. Get the first value in A - register
5. Compare it with the value at next location
6. If they are out of order, exchange the contents of A - register and Memory
7. Decrement D - register content by 1
8. Repeat steps 5 and 7 till the value in D - register become zero
9. Decrement C - register content by 1
10. Repeat steps 3 to 9 till the value in C - register becomes zero
Program For Descending Order

LXI H,4150H Set pointer for array

MOV C,M Load the Count

DCR C Decrement Count

REPEAT: MOV D,C

LXI H, 4151H Load starting address of data array

LOOP: MOV A,M copy content of memory location to Accumulator

INX H

CMP M

JNC SKIP Jump to skip if carry not generated

MOV B,M copy content of memory location to B - Register

MOV M,A copy content of A - Register to memory location

DCX H Decrement content of HL pair of registers

MOV M,B

INX H ; Increment content of HL pair of registers

SKIP: DCR D

JNZ LOOP ;Jump to LOOP if not Zero

DCR C ; Decrement Count

JNZ REPEAT ; Jump to REPEAT if not Zero

HLT ; Terminate Program


Program For Ascending Order

LXI H,4150H Set pointer for array

MOV C,M Load the Count

DCR C Decrement Count

REPEAT: MOV D,C

LXI H, 4151H Load starting address of data array

LOOP: MOV A,M copy content of memory location to Accumulator

INX H

CMP M

JC SKIP Jump to skip if carry not generated

MOV B,M copy content of memory location to B - Register

MOV M,A copy content of A - Register to memory location

DCX H Decrement content of HL pair of registers

MOV M,B

INX H ; Increment content of HL pair of registers

SKIP: DCR D

JNZ LOOP ;Jump to LOOP if not Zero

DCR C ; Decrement Count

JNZ REPEAT ; Jump to REPEAT if not Zero

HLT ; Terminate Program


Problem Statement − Move a block of 8- bit data stored from 4151H to 4160H to a target location
from 4251H to 4260H.
Address Hex Label Mnemonic Comment
Codes

4100 START: LXI H, 4150H Setup HL pair as a pointer for


21 50 41
source memory.

4103 LXI D, 4251H Set up DE pair as a pointer for


11 51 42
destination memory

4106 MOV B, M Set up B to count 16 bytes


46

4107 7E LOOP: MOV A, M Get data byte from source.

4108 12 STAX D Store data byte as destination

4109 23 INX H Point HL to next source location

410A 13 INX D Point DE to next destination

410B 05 DCR B Decrement count

410C JNZ LOOP If counter is not 0, go back to


C2 07 41
transfer next byte.

410F 76 HLT Stop


PROGRAM FOR BCD TO BINARY

Address Hex codes Label Mnemonic Comment

4100 21 50 41 START: LXI H, 4150H Setup HL pair as a pointer for source memory.

4103 46 MOV B, M Get the data in register B

4104 7E : MOV A, M Get data also in register A

4105 E6 0F ANI 0F Masking the MSB of the data

4107 57 MOV D,A Move it to register D

4108 78 MOV A.B Get the original data in accumulator

4109 E6 F0 ANI F0 Masking the LSB of the data

410B 0F RRC Rotate the accumulator content four times


without carry

410C 0F RRC

410D 0F RRC

410E 0F RRC

410F 4F MOV C,A Move accumulator content to register C

4110 AF XRA A Clear the accumulator

4111 1E 0A MVI E 0A Move 0A to register E

4113 81 REPEAT ADD C Add the C register value with accumulator

4114 1D DCR E Decrement the register E content by 1

4115 C2 13 41 JNZ REPEAT If it not equal to zero go to REPEAT label


address.

4118 82 ADD D Add the register D

4119 23 INX H Increment the memory address by 1

411A 77 MOV M,A Move the result to memory location 4151H

411B 76 HLT Stop


Input: 4150 46 (BCD value) Output 4151: 2E

Flow-chart:
Sta
rt

Get the BCD data from the memory 4150H

Move it to Register A and B

Mask the MSB of the data

Move it to Register A and B

Move it to Register D

Get the original data from register B to accumulator A

Mask the LSB of the data

Rotate the accumulator right without carry by 4 times

Move it to register C

Clear the accumulator

Move 0A to register E

Add the C Register value to accumulator

Decrement register E by 1

NO YES
Is E=0?

Add D value with accumulator

Stop
Flow-chart:
Sta
rt

Get the Binary data from the memory


4150H

Move it to Register A

Call procedure power ten

Load HL pair with address 4250H

Move 64H to Register B

Call subroutine BINBCD

Move 0A to register B

Call subroutine BINBCD

Move register A content to Memory

Stop
Address Hex codes Label Mnemonic Comment

4100 21 50 41 START: LXI H, 4150H Set up HL pair as a pointer for source memory.

4103 7E MOV A, M Get the data in register A

4104 CD 08 41 CALL PWRTEN Call procedure PWRTEN

4107 76 HLT Terminate the program

4108 21 60 41 PWRTEN LXI H 4160H Set up HL pair as a pointer for result.

410B 06 64 MVI B 64 Move 64 to Register B

410D CD 17 41 CALL BCDBIN Call subroutine BCDBIN

4110 06 0A MVI B 0A Move 0A to Register B

4112 CD 17 41 CALL BCDBIN Call subroutine BCDBIN

4115 77 MOV M.A Move accumulator content to memory pointed


by HL pair

4116 C9 RET Return to calling routine

4117 36 FF BCDBIN MVI M FF Move FF to memory pointed by HL pair

4119 34 LOOP INR M Increment the memory content by 1

411A 90 SUB B Subtract the content of Register B from


accumulator

411B D2 19 41 JNZ LOOP If A is not equal to zero go to LOOP

411E 80 ADD B Add the content of Register B from accumulator

411F 23 INX H Increment the memory pointer by 1

4120 C9 RET Return to calling routine

1 Input: 4150 FF Output: 4160---- 02 Input: 4150----AD Output: 4160----01


4161---- 05 4161----07
4162------05 4162----03

Shift Left and Right of an 8-bit number by one bit

Address Hex codes Label Mnemonic Comment

4100 21 50 41 START: LXI H, 4150H Set up HL pair as a pointer for source memory.

4103 7E MOV A, M Get the data in register A

4104 07/0F RLC/ RRC Accumulator content is Shifted by 1 bit left


/right

4105 23 INX H Memory pointer is incremented by 1

4106 77 MOV M,A Move result to memory location 4151

4107 HLT Terminate the program

Input: 4150 -------- 24 - 0010 0100 output: 4151---------0100 1000 (48) RRC
4150---------24-0010 0100 Output: 4151----------0001 0010 (12) RLC
Ripple counter generation using 8255
Aim: To use port B of 8255 as a ripple counter.

Hex codes Label Mnemonic Comment


Address

4100 3E 90 START: MVI A 90 Move 90 to A. the control word to set port B as


Output

4102 D3 C6 OUT ADDR Out it to control word register

4104 3E 00 LOOP2 MVI A 00 Move 00 to A

4106 D3 C2 LOOP1 OUT PORT C addr Out it to Port C

4108 CD 14 41 CALL DELAY Call delay routine

410B 3C INR A Increment A by 1


410C FE 0A CPI 0A Compare A with 0A

410E C2 06 41 JC LOOP1 If A<”0A “ go to Loop1

4111 C3 04 41 JMP LOOP2 Go to Loop2

4114 06 AC DELAY MVI B ,AC Move AC data to B register

4116 0E FF LOOP4 MVI C,FF Move FF data to C register

4118 0D LOOP3 DCR C Decrement C register value by 1

4119 C2 18 41 JNZ LOOP3 If C is not equal to zero go to LOOP3

411C 05 DCR B Decrement B register value by 1

411D C2 16 41 JNZ LOOP4 If B is not equal to zero go to LOOP4

4120 C9 RET Return from subprogram

DAC
1 SQUARE WAVE
Aim:
To generate square wave using DAC interface

Address Hex codes Label Mnemonic Comment

4100 3E 00 START: MVI A 00 Move 00 to A.

4102 D3 C8 OUT ADDR Out it to port C

4104 CD 11 41 CALL DELAY Call delay routine

4107 3E 00 MVI A FF Move FF to A

4109 D3 C2 OUT PORT C addr Out it to Port C

410B CD 11 41 CALL DELAY

410E C3 00 41 JMP START

4111 06 01 DELAY MVI B ,01 Move AC data to B register


4113 0E FF LOOP2 MVI C,FF Move FF data to C register

4115 0D LOOP1 DCR C Decrement C register value by 1

4116 C2 15 41 JNZ LOOP1 If C is not equal to zero go to LOOP3

4119 05 DCR B Decrement B register value by 1

411A C2 13 41 JNZ LOOP2 If B is not equal to zero go to LOOP4

411D C9 RET Return from subprogram

FLOW-CHART

Sta
rt

Output the low state 00 of square wave to DAC through A

Call delay subroutine

Output the low state FF of square wave to DAC through A

Call procedure power ten


Call delay subroutine

2 SAW-TOOTH WAVE
Aim: To generate saw-tooth wave using DAC interface

Address Hex codes Label Mnemonic Comment

4100 3E 00 START: MVI A 00 Move 00 to A.

4102 D3 C0 LOOP OUT C0 out it Port C

4104 3C INR A Increment A by 1


4105 C2 02 41 JNZ LOOP If A is not equal to zero go to LOOP

4108 C3 00 41 JMP START Jump to start

FLOW-CHART

Sta
rt

Output the low state 00 of square wave to DAC through A

Output the current state of saw –tooth wave to DAC through B

Increment A by 1

Call procedure
YES power ten
IS A is not 0?

NO

3 TRIANGULAR WAVE
Aim: To generate triangular wave using DAC interface.

Address Hex codes Label Mnemonic Comment

4100 3E 00 START: MVI A 00 Move 00 to A.

4102 D3 C8 LOOP1 OUT C8 out it Port C

4104 3C INR A Increment A by 1

4105 C2 02 41 JNZ LOOP1 If A is not equal to zero go to LOOP1

4108 3E FF MVI A FF Move FF to A.

410A D3 C8 LOOP2 OUT C8 out it Port C

410C 3D DCR A Decrement A by 1


410D C2 0A 41 JNZ LOOP2 If A is not equal to zero go to LOOP2

4110 C3 00 41 JMP START Jump to start

FLOW-CHART

Sta
rt

Output the low state 00 to DAC through A

Output the current state of saw –tooth wave to DAC through Port

Increment A by 1

Call procedure
YES power ten
IS A is not 0?

NO

Output the high state FF to DAC through A

Output the current state of saw –tooth wave to DAC through Port

Decrement A by 1

Call procedure
power ten

YES
IS A is not 0?

NO
STUDY OF 8253 COUNTER
Aim: To study the operation of rate generator, divide by “n” Binary/BCD counter using IC 8253
Control Word Register:

D7 D6 D5 D4 D3 D2 D1 D0
SC1 SC0 RL1 RL0 M2 M1 M0 BCD

SC- Select Counter 00----counter 0 RL (Read/Load) 00-- Counter latching operation


01----counter 1 01---Read/Load LSB only
10----counter 2 10---Read/Load MSB only
11----Illegal 11---Read/Load LSB first then MSB
Mode selection BCD 0-----Binary counter 16-bits
M2 M1 M0 MODE 1------BCD
0 0 0 Mode 0
0 0 1 Mode 1
X 1 0 Mode2
X 1 1 Mode 3
1 0 0 Mode 4
1 0 1 Mode 5

Rate generator: Use 8253 in Mode 2 to act as a divide by –N counter. N=16 decimal =10 in
Hexa- decimal
Control Word Register---- 94
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 1 0 1 0 0
Address Hex codes Label Mnemonic Comment

4100 3E 94 START: MVI A 94 Move 94 to A.

4102 D3 13 OUT CWR addr out it CWR

4104 3E 10 MVI A 10H Get the count value N

4106 D3 12 OUT 12 12 is address of counter 2

4108 76 HLT Stop

94 is the CW for Mode 2 operation for binary counting. 13 –address for control
12 for counter 2

BCD counter N=10

Address Hex codes Label Mnemonic Comment

4100 3E 94 START: MVI A 95 Move 95 to A.

4102 D3 13 OUT CWR addr out it CWR

4104 3E 10 MVI A 10H Get the count value N

4106 D3 12 OUT 12 12 is address of counter 2

4108 76 HLT Stop

Mode-3 Square Wave Generator

Use 8253 in Mode 3 as a square wave generator


Control Word Register---- 96
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 1 0 1 1 0

Address Hex codes Label Mnemonic Comment

4100 3E 96 START: MVI A 96H Move 96 to A.

4102 D3 13 OUT CWR addr out it CWR

4104 3E 10 MVI A 10H Get the count value N

4106 D3 12 OUT 12 12 is address of counter 2

4108 76 HLT Stop

For N=10H=16 Decimal. The output remains high for 8 clock cycles and then low for next 8
clock cycles.

BCD

Address Hex codes Label Mnemonic Comment

4100 3E 97 START: MVI A 97H Move 97 to A.

4102 D3 13 OUT CWR addr out it CWR

4104 3E 10 MVI A 10H Get the count value N

4106 D3 12 OUT 12 12 is address of counter 2

4108 76 HLT Stop

N=10. For the first 5 clock output is high and then low for next 5 clock cycles.
Rolling message program –8085 microprocessor

Address Hex codes Label Mnemonic Comment

4100 3E 10 START: MVI A 10H Move 10 to A.

4102 D3 ** OUT CWR addr out it CWR

4104 3E CC MVI A CC Clear display RAM

4106 D3 ** OUT CNT Out it CNT addr** is address of CNT

4108 3E 90 MVI A 90 Move 90 to A register

410A D3 ** OUT CNT Out it CNT addr** is address of CNT

410C 21 00 42 LXI H 4200 Set up 4200H as memory pointer

410F 4E MOV C, M Get the count value in C register

4110 23 INX H Increment the memory pointer

4111 7E LOOP1 MOV A, M Move the display character code to A register

4112 D3 *** OUT PORT ADDR Out it to the port address

4114 CD 1F 41 CALL DELAY Call the delay routine

4117 23 INX H Memory pointer is incremented by 1

4118 0D DCR C Decrement the value of C register by 1

4119 C2 11 41 JNZ LOOP1 If it not equal to zero go to LOOP1 statement

411C C3 00 41 JMP START Unconditional transfer to starting address of the


program

411F 16 A0 DELAY MVI D A0 Move A0 immediately to register D

4121 1E FF LOOP3 MVI E FF Move FF immediately to register E

4123 1D LOOP2 DCR E Decrement the value of register E by 1

4124 C2 23 41 JNZ LOOP2 If it not equal to zero go to LOOP2 statement

4127 15 DCR D Decrement the value of register D by 1

4200H ------10H (Number of character displayed


4128 C2 21 41 JNZ LOOP 3 If it not equal to zero go to LOOP3 statement

412B C9 RET Return to calling program

Memory address Display code CHARACTER


4201 FF BLANK
4202 FF BLANK
4203 28 G
4204 0C O
4205 1A D
4206 FF BLANK
4207 FF BLANK
4208 9F I
4209 29 S
420A FF BLANK
420B FF BLANK
420C 28 G
420D FA R
420E 68 E
420F 88 A
4210 78 T

D7 D6 D5 D4 D3 D2 D1 D0
A3 A2 A1 A0 B3 B2 B1 B0
d c b a dp g f e
0 for active 1 in active
1The following program select channel 0 and start analog to digital conversion by using
ALE signal.
ORG 4100H
4100 3E 10 START: MVI A, 10H Select Channel 0 and Make
4102 D3 C8 OUT 0C8H ALE Low
4104 3E 18 MVI A, 18H Make ALE High
4106 D3 C8 OUT 0C8H
4108 3E 10 MVI A, 10H Make ALE Low
410A D3 C8 OUT 0C8H
410C 76 HLT
PROCEDURE
1. Place jumper J2 in C position.
2. Place jumper J5 in A position.
3. Enter and execute the program.
4. Vary the analog input (using trimpot) and view the corresponding digital value in
the led display.

2 Initiating the analog to digital conversion process by means of software, is sometime


necessary. Execute the program given below, which converts the analog input at
Channel 0 and displays the output with the LEDs.
ORG 4100H
4100 3E 10 START: MVI A, 10 Select Channel 0 and Make
4102 D3 C8 OUT 0C8H ALE Low
4104 3E 18 MVI A, 18 Make ALE High
4106 D3 C8 OUT 0C8H
4108 3E 01 MVI A, 01 SOC Signal High
410A D3 D0 OUT 0D0H
410C AF XRA A DELAY
410D AF XRA A
410E AF XRA A
410F 3E 00 MVI A, 00 SOC Signal Low
4111 D3 D0 OUT 0D0H
4113 76 HLT

PROCEDURE
1. Place jumper J2 in A position.
2. Place jumper J5 in A position.
3. Enter and execute the program.
4. Vary the analog input (using trimpot) and view the corresponding digital value in the
LED display.
3 In a real time application, input of data and processing of data are indispensable.
The following programs initiate the conversion process, checks the EOC pin of ADC
0809 as to whether the conversion is over and then inputs the data to the processor. It
also instructs the processor to store the converted digital data at RAM location 4150
(Hex).
ORG 4100H
4100 3E 10 START: MVI A, 10 Select Channel 0 and Make
4102 D3 C8 OUT 0C8H ALE Low
4104 3E 18 MVI A, 18 MAKE ALE HIGH
4106 D3 C8 OUT 0C8H
4108 3E 01 MVI A, 01 SOC Signal High
410A D3 D0 OUT 0D0H
410C AF XRA A Delay
410D AF XRA A
410E AF XRA A
410F 3E 00 MVI A, 00 SOC Signal Low
4111 D3 D0 OUT 0D0H
4113 DB D8 LOP: IN 0D8H Check for EOC
4115 E6 01 ANI 01
4117 FE 01 CPI 01
4119 C2 13 41 JNZ LOP
411C DB C0 IN 0C0H Read Data from ADC
411E 32 50 41 STA 4150H
4121 76 HLT
PROCEDURE
1. Place jumper J2 in A position.
2. Place jumper J5 in A position.
3. Enter and execute the program.
4. Vary the analog input (using trimpot) and verify the digital data displayed with that
data stored in memory location 4150h.

KEYBORD INTERFACE
The following program waits for a key to be pressed in the keyboard, reads the same and stores it
in the location 4200.
PROGRAM:
Reading from 8279
ORG 4100H
4150 DB C2 LOOP: IN CNT FIFO Status
4152 E6 07 ANI 07 Check for a key
4154 CA 50 41 JZ LOOP closure
4157 3E 40 MVI A, 40H set 8279 for a
4159 D3 C2 OUT CNT read of FIFO RAM
415B DB C0 IN DAT
415D 32 00 42 STA 4200 Key code at 4200
4160 76 HLT
When you press the Key 0, the data entered at the FIFO RAM is C0.

ROLLING DISPLAY:
To display the rolling message 'HELP US' in the display.
The initialization of 8279 is same as that of Example-1. Then, the data is fetched from address
412CH and displayed in the first digit of the display. The next data is displayed in the second digit
of the display, since in the command word for 'write display RAM' the Auto Increment flag is set.
A time delay is given between successive digits for a lively display.
Rolling Display with 8279 Int. Board
ORG 4100H
CNT EQU 0C2H
DAT EQU 0C0H
POINTER EQU 412CH
4100 21 2C 41 START: LXI H, POINTER Set pointer = 412CH
4103 16 0F MVI D, 0FH Initialize counter
4105 3E 10 MVI A, 10H
4107 D3 C2 OUT CNT Set mode and display
4109 3E CC MVI A, 0CCH Clear Display
410B D3 C2 OUT CNT
410D 3E 90 MVI A, 90H Write display
410F D3 C2 OUT CNT
4111 7E LOP: MOV A, M
4112 D3 C0 OUT DAT
4114 CD 1F 41 CALL DELAY
4117 23 INX H Increment the pointer
4118 15 DCR D Decrement the counter
4119 C2 11 41 JNZ LOP Jump if non-zero to
411C C3 00 41 JMP START display the next chr.
411F 06 A0 DELAY: MVI B,0A0H
4121 0E FF LOP1: MVI C,0FFH
4123 0D LOP2: DCR C
4124 C2 23 41 JNZ LOP 2
4127 05 DCR B
4128 C2 21 41 JNZ LOP1
412B C9 RET
412C FF FF FF FF
4130 FF FF FF FF
4134 98 68 7C C8
4138 1C 29 FF FF

You might also like