Nothing Special   »   [go: up one dir, main page]

8085 Expts

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

EEL331:

MICROPROCESSORS AND
MICROCONTROLLERS LAB
(2019 Scheme)
8085 Microprocessor Experiments
EXPERIMENT-3
STUDY OF 8085 MICROPROCESSOR KIT

INTRODUCTION

INTEL 8085 is an 8-bit general-purpose microprocessor capable of addressing 64KB of


memory. The device has forty pins and can operate with a + 5V single power supply. The
microprocessor has a set of instructions designed internally, to manipulate data and communicate
with peripherals. It can be programmed to perform functions on given data by selecting necessary
instructions from its set.

An 8-bit register, A called the Accumulator is the primary source and destination for one-
byte and two-byte instructions. All data transfers between the CPU and I/O devices are performed
through the accumulator. All arithmetic and Boolean instructions take one of the operands from
the accumulator and return the result to the accumulator. Apart from the accumulator, 8085 has
six general purpose registers viz., B, C, D, E, H and L to store 8-bit data. These registers can be
combined as register pairs- BC, DE and HL to perform 16-bit operations.

SPECIFICATIONS OF MICRO-85 EB KIT

Hardware Specifications

1) Processor, Clock frequency: Intel 8085A at 6.144 MHz clock.

2) Memory:

Monitor EPROM : 0000 - 1FFF

EPROM- Expansion : 2000 - 3FFF & C000 - FFFF

System RAM : 4000 - 5FFF

Monitor Data Area : 4000 - 40FF (Reserved)

User RAM Area : 4100 - 5FFF

RAM- Expansion : 6000 – BFFF

Note: The RAM area from 4000 – 40FF should not be accessed by the user since it is used as
scratch pad by the Monitor program.
3) Display:

Six digit, 7 segment red LED display. The first four digits are for address display and the
remaining two digits are for data display.

4) Keyboard:

Twenty-one key soft keyboard including command keys and hexadecimal keys.

5) Battery Backup:

On-board battery backup facility is provided for the available RAM.

6) Power Supply Specifications: (External)

Input : 230 V AC @ 50 Hz

Output : + 5V @ 3A

: +12 V @ 250 mA

: -12 V @ 250 mA

Software Specifications

Out of the 21 keys in the keyboard, 16 are hexadecimal keys and the remaining are standalone
keys. The following is a simple description of the key functions.

KEY FUNCTION SUMMARY

RES Allows the user to terminate any present activity and return the microprocessor
to an initialized state

SUB For substituting memory contents when NEXT key is pressed

GO Start running a particular program

DEC Decrement address by one and display its contents

EXEC Execute a particular program after selecting the address through GO command

NEXT Increment address by one and display its contents

The 16 hexadecimal keys have a dual role to play:

(i) It functions as a Hex key entry when an address or data entry is required.

(ii) It functions as a Register key entry during register command.


PROCEDURE

To enter data at memory locations:

To enter data at memory locations, SUB keyboard command is used. For example, to enter data starting
from memory location 4100H, the following key sequence has to be used.
RES→ SUB→4100→ NEXT
The data field is displayed where 8-bit data can be entered. Press NEXT again to access the
succeeding memory location (4101H).

Note: Pressing NEXT after entry of desired data will put the entered data to the memory location
displayed then.

To examine memory locations:

To examine memory locations, SUB keyboard command is used. To examine the contents of the location
for 4500H, the following key sequence has to be used.
RES→ SUB→4500→ NEXT

To view the content of next memory location in the data field:

To view the content of the next location 4501H, press NEXT. The address is changed to 4501H
and the corresponding content is displayed.

To execute a program:

In order to execute a program, the following key sequence has to be entered. For example, to
execute a program stored at location 4100H (starting address).
RES → GO → 4100 →EXECUTE

Now “E” is displayed in the status field and control is transferred to the address entered. To check
the result at a particular location, use SUB command again. To exit from the execution, press the
RESET (RES) key.

CONCLUSION

The internal architecture as well as the hardware and software specifications of MICRO-85 EB
are detailed.
EXPERIMENT-4

DATA TRANSFER USING DIFFERENT ADDRESSING MODES OF 8085 AND BLOCK


TRANSFER

AIM:

(1) To illustrate various addressing modes using data transfer operations.


(2) To write and execute an ALP to transfer a block of data from one set of memory
locations to another.

1. DATA TRANSFER OPERATIONS

Program I- Immediate, Direct and Register Addressing


EXAMPLE: To initialize data to registers as shown below:
(A) =23H, (B) =50H, (C) =1AH, (D) =63H, (E) =FEH, (H) =76H and (L) = ACH
Assume that the data to initialize D and E registers are at memory locations 4150H and 4151H
i.e., (4150) = FEH and (4151) =63H.

Memory Machine Mnemonics Comments


Address Code
4100 01,1A,50 LXI B, 501AH Load BC with immediate data of 501A
(B)= 50H, (C)= 1AH
4103 3A,50,41 LDA 4150H Load A with direct data of 4150H i.e., FEH

4106 5F MOV E, A (E)=FEH, register addressing

4107 3A,51,41 LDA 4151H Load A with direct data of 4151H i.e., 63H

410A 57 MOV D, A (D)= 63H

410B 3E,23 MVI A, 23H Load accumulator with immediate data of


23H
410D 21,AC,76 LXIH, 76ACH Load immediate data of 76AC to HL pair
(H)=76H, (L)= ACH
4110 76 HLT End of the program
Note:
• All addresses and data are in hex-form denoted by symbol H unless otherwise specified.
• The symbol (X) denotes contents of X where X can be any register or memory location of 8085.

PROCEDURE
(i) Key in the opcodes from the address shown into the trainer kit.
(ii) Enter the data at 4150H and 4151H.
(iii) Single step the program and check the register contents at every point.
(iv) Ensure that the registers contain the data as specified.

Program II- Register Indirect Addressing


EXAMPLE: To load from memory location 4150H and store at location 4160H. (4150H) =29H.

Memory Machine Mnemonics Comments


Address Code
4100 21,50,41 LXI H, 4150H Initialize HL as memory pointer for source

Initialize DE as memory pointer for


4103 11,60,41 LXI D, 4160H
destination
4106 7E MOV A,M Content of 4150H is moved to the accumulator

4107 12 STAX D Content of accumulator is moved to 4160H

4108 76 HLT End of the program

PROCEDURE
(i) Key in the opcodes from the address specified.
(ii) Enter the data at 4150H.
(iii) Execute the program and check for result at 4160H.

DATA : (4150) = 29H


RESULT : (4160) = 29H
Program III- Direct Addressing (16-bit)
16-bit loading of data using direct addressing is supported only by HL pair. However, DE pair can
also be loaded with 16-bit data from HL register using the XCHG instruction. Let (4150) =99,
(4151) =77 and (DE) =005B. The content of DE pair has to be stored in 4160H and 4161H.

Memory Machine Mnemonics Comments


Address Code
4100 11,5B,00 LXI D, 005BH Initialize (D)=00, (E)=5B

4103 2A,50,41 LHLD 4150H Load direct data 9977 to HL. (L) =99, (H)=77

4106 EB XCHG (D) =77, (H)=00, (E) =99, (L) =5B

4107 22,60,41 SHLD 4160H Store direct data from HL to memory. (4160)=5B,
(4161) =00
410A 76 HLT End of the program

PROCEDURE
(i) Key in the opcodes from the address specified.
(ii) Enter the data at 4150H and 4151H.
(iii) Execute the program and check for results at 4160H and 4161H.

DATA : (4150) = 99H


(4151) = 77H
(DE) = 005BH
RESULT : (4160) = 5BH
(4161) = 00H

2. BLOCK TRANSFER OF DATA

Ten data bytes are stored in memory locations from 4500H to 4509H. This block of data is to be
transferred to memory locations from 4700H to 4709H. The HL register pair is used as a pointer
for the source memory and DE pair as pointer for the destination memory. A counter is set up using
the register C. Initially, the first number from the source is moved to the accumulator. The data in
the accumulator is then moved to the first location of destination. The address pointers are
subsequently incremented to point to the next source and destination locations and the counter is
decremented to indicate that one byte is transferred. If the counter is not zero, the above process
will continue. If the counter is zero, it implies that all the ten bytes are transferred from the source
to the destination.

Memory Machine Label Mnemonics Comments


Address Code
4100 21,00,45 LXI H, 4500H Set up HL as a pointer of source
memory
Set up DE as a pointer for destination
4103 11,00,47 LXI D, 4700H memory
4106 06,0A MVI B, 0AH Set up the counter to count 10 data

4108 7E NEXT : MOV A, M Get data from source to accumulator

4109 12 STAX D Store data in destination

410A 23 INX H Point HL to next source location

410B 13 INX D Point DE to next destination

410C 05 DCR B Decrement count

410D C2,08,41 JNZ NEXT Jump to transfer the next data if count is
non-zero
4110 76 HLT End the program

DATA 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509

22 A5 B2 99 7F 37 14 05 C2 42

RESULT 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709

22 A5 B2 99 7F 37 14 05 C2 42

RESULT

(i) Data transfer operations are illustrated using various addressing modes of 8085.

(ii) Assembly language program for block data transfer is developed and executed using
the 8085 kit.
EXPERIMENT-5

ARITHMETIC OPERATIONS USING 8085


AIM:
To write and execute the following assembly language programs using 8085:
(i) Addition of two 8-bit numbers
(ii) Subtraction of two 8-bit numbers
(iii) Addition of an array of 8-bit numbers
(iv) Addition of two 16-bit numbers
(v) Multiplication of two 8-bit numbers

1. Addition of two 8-bit binary numbers


Theory:
The 8-bit binary numbers are stored in locations 4501H and 4502H. HL pair is used as the address
pointer and register C is cleared to store the carry. The result obtained after addition of data bytes
is available in the accumulator. It is then stored in the location 4503H. The carry is stored in 4504H.
Algorithm:
1. Initialize address pointer. Get the first number in the accumulator.
2. Increment address pointer to get the second number and clear carry register.
3. Add the memory content indicated by the address pointer with the accumulator content.
4. Jump on if no carry. Otherwise, increment the carry register.
5. Store the result and carry in specified memory locations.

Addition of two 8-bit binary numbers


Memory Machine Label Mnemonics Comments
Address Code
4100 21,01,45 LXI H, 4501H Load the address of first number in HL
pair
MOV A, M Move the first number to the
4103 7E accumulator
4104 23 INX H Load the address of second number in
HL pair
4105 0E,00 MVI C, 00H Initialize register C to store Carry

4107 86 ADD M Add first and second numbers i.e., (A) +


(M).
4108 D2,0C,41 JNC AHEAD If there is no carry, go to AHEAD

410B 0C INR C If there is a carry, increment register C

410C 32,03,45 AHEAD: STA 4503H Store the result (sum) available in the
accumulator to the location 4503H
410F 79 MOV A, C Move content of register C to the
accumulator
4110 32,04,45 STA 4504H Store carry in the next location 4504H

4113 76 HLT End of the program

Note: For BCD addition of two 8-bit binary numbers, the DAA instruction is used after ADD
instruction in the above program to convert the result to BCD format.

2. Subtraction of two 8-bit binary numbers

Theory:

The 8-bit binary numbers are stored in locations 4501H and 4502H. Initially register C is cleared
to store carry (borrow), if any. The result obtained after subtraction of data bytes is available in
the accumulator. The 2’s complement of the result is determined before storing it in the location
4503H. The borrow is stored in 4504H.

Algorithm:
1. Initialize address pointer. Get the first number in the accumulator.
2. Increment address pointer to get the second number and clear carry register.
3. Subtract the second number from the first.

4. Jump on if no borrow. Otherwise, increment the borrow register.

5. Find two’s complement of the result in accumulator if there is a borrow.


6. Store the result and borrow in specified memory locations.

Subtraction of two 8-bit binary numbers


Memory Machine Label Mnemonics Comments
Address Code
4100 21,01,45 LXI H, 4501H Load the address of first number in HL
pair
MOV A, M Move the first number to the
4103 7E accumulator
4104 23 INX H Load the address of second number in
HL pair
4105 0E,00 MVI C, 00H Initialize register C to store Carry
(Borrow)
4107 96 SUB M Subtract second number from the first
number
4108 D2,0E,41 JNC AHEAD If there is no borrow, go to AHEAD

410B 0C INR C If there is a borrow, increment borrow


register
410C 2F CMA Find 1s complement of the result

410D 3C INR A Add one to get 2’s complement

410E 32,03,45 AHEAD: STA 4503H Store the result available in the
accumulator to the location 4503H
4111 79 MOV A, C Move content of register C to the
accumulator
4112 32,04,45 STA 4504H Store borrow in the next location 4504H

4115 76 HLT End of the program

3. Addition of an array of 8-bit binary numbers

Theory:

The size of the array is specified in the memory location 4500H. The data bytes are available from
locations 4501H onwards. Initially, the accumulator and register B are cleared to store
respectively, the sum and carry. Register C is set up as a counter. The LSB of the result (sum) is
stored in 4700H and MSB (carry) in 4701H.

Algorithm:
1. Initialize address pointer and set up a counter.
2. Initialize registers to save sum and carry.
3. Add a byte in the memory with the accumulator content.
4. If a carry is generated, increment the carry register.
5. Increment address pointer and decrement the counter. If counter is zero, stop. Otherwise,
repeat step 3 until all bytes are added.
6. Store the results in specified memory locations.
Addition of an array of 8-bit binary numbers
Memory Machine Label Mnemonics Comments
Address Code
4100 21,00,45 LXI H, 4500H Load the address of count in HL pair

MOV C, M Move the count to register C


4103 4E
4104 AF XRA A Clear the accumulator

4105 47 MOV B, A Clear register B to store MSB’s of sum


(carry)
4106 23 LOOP: INX H Load the address of first number in HL
pair
4107 86 ADD M Add the first number with the content of
the accumulator
4108 D2,0C,41 JNC AHEAD If there is no carry, go to AHEAD

410B 04 INR B If there is a carry, increment the content


of register B
410C 0D AHEAD: DCR C Decrement count

410D C2,06,41 JNZ LOOP Is the counter zero? If no, then repeat to
fetch the next number
4110 32,00,47 STA 4700H If yes, store the result in 4700H

4113 78 MOV A,B Move the carry to the accumulator

4114 32,01,47 STA 4701H Store carry in 4701H

4117 76 HLT End of the program

4. Addition of two 16-bit binary numbers

Theory:

The first 16-bit number is stored in memory locations 4501H and 4502H. The second 16-bit
number is stored in locations 4503H and 4504H. Register C is used to store the carry resulting
from the addition of data bytes. The result available in HL register pair is transferred to memory
locations 4505H and 4506H. The carry is stored in 4507H.

Algorithm:

1. Load HL pair with the address of the first 16-bit number.

2. Copy the number to DE register pair.


3. Load HL pair with the address of the second number.

4. Initialize carry register.

5. Add the contents of the two register pairs.

6. Jump on if no carry. Otherwise, increment the carry register.

7. Store the result and carry in specified memory locations.

Addition of two 16-bit binary numbers


Memory Machine Label Mnemonics Comments
Address Code
4100 2A,01,45 LHLD 4501H Load the first 16-bit number in H and L
registers
XCHG Exchange the contents of H and L with
4103 EB D and E
4104 2A,03,45 LHLD 4503H Load the second 16-bit number in H and
L registers
4107 0E,00 MVI C,00H Clear register C to store carry

4109 19 DAD D Add both numbers

410A D2,0E,41 JNC AHEAD If there is no carry, go to AHEAD to


store the result
410D 0C INR C If there is a carry, increment the
contents of register C
410E 22,05,45 AHEAD: SHLD 4505H Store the result in 4505H and 4506H

4111 79 MOV A, C Move the content of register C (carry) to


the accumulator
4112 32,07,45 STA 4507H Store the carry in 4507H

4115 76 HLT End of the program

5. Multiplication of two 8-bit binary numbers


Theory:
The multiplicand is stored in the memory location 4501H and multiplier in the location 4502H.
Since 8085 has no instruction to multiply data bytes, multiplication is performed by repeated
addition. Here, the multiplicand is added to itself repeatedly. The number of times the addition has
to be performed is decided by the multiplier. The result is stored in locations 4503H and 4504H.
Algorithm:

1. Initialize memory pointers to get the address of the first (multiplicand) and second
numbers (multiplier). Move the numbers to registers.

2. Initialize accumulator and carry register. Set the multiplier as a counter.

3. Add multiplicand to itself. If a carry is generated, increment the carry register.

4. Decrement counter. If counter is zero, stop. Otherwise, repeat the previous step.

5. Store the result and carry in specified memory locations.

Multiplication of two 8-bit binary numbers


Memory Machine Label Mnemonics Comments
Address Code
4100 21,01,45 LXI H, 4501H Load the address of first number
(multiplicand) in HL pair
MOV B, M Move the first number to register B
4103 46
4104 23 INX H Load the address of second number
(multiplier) in HL pair
4105 56 MOV D, M Move the second number to register D

4106 3E,00 MVI A, 00H Initialize the accumulator content to


00H
4108 4F MOV C, A Clear register C to store carry

4109 80 LOOP: ADD B Add content of A with the content of B

410A D2,0E,41 JNC AHEAD Jump on no carry to AHEAD

410D 0C INR C Increment content of register C

410E 15 AHEAD: DCR D Decrement content of register D

410F C2,09,41 JNZ LOOP Jump on no zero to LOOP

4112 32,03,45 STA 4503H Store the result in the location 4503H

4115 79 MOV A,C Move carry to the accumulator

4116 32,04,45 STA 4504H Store carry in the location 4504H

4119 76 HLT End of the program


PROCEDURE

Addition, subtraction, and multiplication of two 8-bit binary numbers

Enter the machine codes corresponding to each program from memory locations starting at 4100H.
Enter the data at the memory locations 4501H and 4502H. Execute each program and verify the
results at 4503H and 4504H.

Addition of an array of 8-bit binary numbers

Enter the machine codes from memory locations starting at 4100H. Specify the array size at
4500H. Enter the data from the memory location starting at 4501H. Execute the program and
verify the results at 4700H and 4701H.

Addition of two 16-bit binary numbers

Enter the machine codes from memory locations starting at 4100H. Enter the first 16-bit number
at locations 4501Hand 4502H. Enter the second 16-bit number at 4503H and 4504H. Execute the
program and verify the results at 4505H, 4506H and 4507H.

RESULT

The assembly language programs for addition, subtraction and multiplication of data bytes were
developed and executed using the 8085 microprocessor kit.
EXPERIMENT-6

SORTING AND CODE CONVERSION USING 8085

AIM
To write and execute assembly language programs using 8085 to:
(i) sort an array of ten 8-bit numbers in ascending (descending) order
(ii) convert a BCD number to its binary equivalent
(iii) convert a binary number to its BCD equivalent

1. Sorting an array in ascending order

Theory:
Bubble sort algorithm is used to sort the given data. The algorithm makes repeated comparisons
of adjacent data bytes and pushes the higher value down the array. i.e., In this type of sorting, the
first and second bytes are compared and the larger of the two numbers is kept in the second address.
Then second and third bytes are compared and the larger is kept in the third address and so on.
After one cycle (i.e., N-1 comparisons, where N is the number of data bytes), the largest number
will be in the last address. In the second cycle of bubble sort (i.e., N-2 comparisons), the second
largest number will be stored in the last but one memory location Thus, the processor goes through
several cycles and arranges the numbers in ascending order. Both the number of passes and the
number of comparisons will be less than the number of data in the array by one.

Algorithm:
1. Set the cycle counter at N-1, where N is the length of the array.
2. Copy the content of cycle counter to comparison counter. Take the first data to the
accumulator.
3. Compare with the next number. If next number is larger than the next, go to the next step.
Otherwise, swap the contents of consecutive memory locations.
4. Decrement comparison counter. If it is not zero, go to Step 3.
5. Decrement cycle counter. If it is zero, stop. Otherwise go to Step 2.
Program 1: Sorting an array in ascending order
Memory Machine Label Mnemonics Comments
Address Code
4100 OE, 09 MVI C, 09H Set cycle counter to N-1 where N is the
array size
4102 51 BACK: MOV D,C Set comparison counter to N-1
4103 21,01,45 LXI H, 4501H Load starting address of the array

4106 7E LOOP: MOV A, M Copy the first number to the


accumulator
4107 23 INX H Point HL to the next location i.e., 4502H
4108 BE CMP M Compare first number in the
accumulator with the second number in
memory location 4502H
4109 DA,11,41 : JC NEXT If there is a carry, then smaller number
is in the accumulator. Go to NEXT
410C 46 MOV B, M Otherwise, move smaller number
temporarily to register B
41OD 77 MOV M, A Move larger number in the accumulator
to location 4502H
41OE 2B DCX H Decrement HL pair to access the
location 4501H
410F 70 MOV M,B Move the smaller number to 4501H
4110 23 INX H Increment HL pair to access the location
4502H
4111 15 NEXT: DCR D Decrement the comparison counter

4112 C2,06,41 JNZ LOOP Jump to LOOP if non-zero

4115 0D DCR C Decrement the cycle counter

4116 C2,02,41 JNZ BACK Jump to BACK if non-zero

4119 76 HLT End of the program

Note: To sort the array in descending order, the mnemonic JC NEXT corresponding to
memory location 4109 is changed to JNC AHEAD. The opcode at location 4109 is changed
from DA to D2.
2. BCD to Binary conversion

Theory:
BCD stands for Binary Coded Decimal. It is a system that represents numbers in a format similar
to decimal. Only 10 valid BCD digits are present i.e., 0 to 9. A BCD byte can store values from 00
to 99. The conversion of a BCD number into its binary equivalent employs the principle of
positional weighting in a given number. In order to convert a 2-digit BCD number into its binary
equivalent, first the digits are separated and each digit is multiplied by its position and added
together. The required steps are as follows:
(i) Load the BCD number in the accumulator.
(ii) Unpack the 2-digit BCD number into two separate digits. Let the left digit be BCD 2
and the right one BCD1.
(iii) Multiply BCD2 by 10 and add BCD1 to it.

Algorithm:
(i) Separate BCD1 of the BCD number by ANDing the number with 0FH and store it in a
register.
(ii) Separate BCD2 by ANDing the number with F0H and shift the bits to the right four
times. Multiply BCD2by 10.
(iii) Add the product with BCD1.

PROGRAM 2: BCD to Binary Conversion


Memory Machine Label Mnemonics Comments
Address Code
4100 21,00,45 LXI H, 4500H Load the address of the BCD number in the
HL pair
7E MOV A,M Move the BCD number to the accumulator
4103
4104 Move the number to register B
47 MOV B, A
4105 E6, 0F ANI 0FH Logically AND immediate the accumulator
content with OFH to obtain BCD1
4107 4F MOV C, A Store BCD1 in register C
4108 78 MOV A, B Restore the original value of the accumulator
by moving the content in B to A
4109 E6, F0 ANI FOH AND immediate the accumulator content with
FOH
410B CA, 1B, 41 JZ SKIP If the value in the accumulator equals zero,
then BCD1 is the final answer. Store it in an
arbitrary memory location
410E 0F RRC Else, shift the accumulator content to the right
4 times to obtain BCD2. Next step is to
multiply BCD2 by 10
410F 0F RRC
4110 0F RRC
4111 0F RRC
4112 57 MOV D, A Move BCD2 to register D
4113 AF XRA A Clear the accumulator
4114 1E,0A MVI E, OAH Initialize register E with OAH as the counter
4116 82 SUM: ADD D Add D to it E number of times
4117 1D DCR E Decrement the content of register E
4118 C2,16,41 JNZ SUM Is multiplication complete? If not, then go to
SUM and add again
411B 81 SKIP: ADD C Add the content of C with the content of the
accumulator
411C 32,00,47 STA 4700H Store the result in memory location 4700H
411F 76 HLT End of the program

3. Binary to BCD conversion


Theory:
An unsigned 8-bit binary number has a range from 00H to FFH. Its equivalent BCD number is 00
to 255. Thus, to represent a binary number in BCD, a maximum of twelve bits or three BCD digits
are required which are represented as BCD3 (MSB), BCD2, and BCD1 (LSB). The steps for
conversion are:
(i) If the binary number is less than 100, go to Step (ii); otherwise, subtract 100 repeatedly
until the remainder is less than 100. The quotient is BCD3.
(ii) If the number is less than 10, go to Step (iii); otherwise, subtract 10 repeatedly until the
remainder is less than 10. The quotient is BCD2.
(iii) The remainder from Step (ii) is BCD1.
Algorithm:
(i) Find the number of hundreds in the binary number. For that, subtract 100 (64H) from
the binary number.
(ii) Find the number of tens in the remainder obtained by subtracting 10 (0AH).
(iii) The remainder obtained by subtracting tens is units. Arrange the number of hundreds,
tens and units in the proper positions to obtain the equivalent BCD number.

PROGRAM 3: Binary to BCD Conversion

Memory Machine Label Mnemonics Comments


Address Code
4100 3A,00,45 LDA 4500H Load accumulator with the content of 4500H

4103 06,00 MVI B, 00H Clear register B


4105 48 MOV C,B Clear register C
4106 FE,64 LOOP1 : CPI 64H Compare the accumulator content with 100
4108 DA,11,41 JC AHEAD If the accumulator content is less than 100, go
to AHEAD
410B D6,64 SUI 64H Subtract 100 from the accumulator content
410D 04 INR B Increment register B to get the quotient
410E C3,06,41 JMP LOOP1 Repeat until the remainder is less than 100
4111 FE,0A AHEAD: CPI 0AH Compare the accumulator content with 10
4113 DA,1C,41 JC GO If the accumulator content is less than 10, go
to store BCD3
4116 D6,0A SUI OAH Subtract 10 from the accumulator content
4118 0C INR C Increment register C
4119 C3,11,41 JMP AHEAD Repeat until the remainder is less than 10
411C 32,01,45 GO: STA 4501H Store BCD1 in the location 4501H
411F 79 MOV A,C Move the content of register C to the
accumulator
4120 32,02,45 STA 4502H Store BCD2 in 4501H
4123 78 MOV A,B Move the content of register B to the
accumulator
4124 32,03,45 STA 4503H Store BCD3 in the location 4503H
4127 76 HLT End of the program
PROCEDURE
1. Sorting in ascending (descending order)
(i) Enter the machine codes from memory location 4100H onwards.
(ii) Set registers C and D as cycle counter and comparison counter respectively.
(iii) Enter the unsorted array of ten numbers from memory location 4501H onwards.
(iv) Execute the program
(v) Verify the result (sorted array) from memory locations starting at 4501H.
(vi) Modify the above program to sort in descending order by changing the instruction JC
to JNC.
2. BCD to Binary conversion
(i) Enter the program from memory location 4100H onwards.
(ii) Enter a valid BCD number at 4500H.
(iii) Execute the program and verify the binary equivalent in memory location 4700H.
3. Binary to BCD conversion
(i) Enter the program from memory location 4100H onwards.
(ii) Enter a binary number at memory location 4500H.
(iii) Execute the program and verify the equivalent BCD value in locations 4501H,
4502H, and 4503H.

RESULT
The following assembly language programs are developed and executed using the 8085
microprocessor kit.
(i) Sorting an array of ten numbers in ascending and descending order.
(ii) Converting a BCD number to its binary equivalent and vice-versa.
EXPERIMENT-7

WAVEFORM GENERATION USING 8085

AIM
To write and execute assembly language programs to generate the following waveforms:
(i) Sawtooth wave
(ii) Triangular wave
(iii) Square wave with equal and unequal delay

PRINCIPLE
In order to generate waveforms using a microprocessor, it must have input-output (I/O)
ports interfaced to it. IC 8255 is a Programmable Peripheral Interface that operates on +5V DC
supply. It has three 8-bit ports- Port A, Port B and Port C, the functions of which are defined by
writing a control word in a Control Register. The output from the microprocessor is in digital
format whereas the waveforms to be generated are analog signals. Hence, a Digital-to-Analog
Converter (DAC) is required for the conversion. The DAC is connected to Port A of the 8255.
IC 8255 needs to be initialized before use. Initialization includes setting the mode of
operation and framing an appropriate control word. Here, 8255 is set up in I/O mode with all ports
as output ports. The corresponding control word is 80H, which is written onto the control register
whose address is 03H. The data sent out from the microprocessor can be directed to any port of
8255. Each Port has a unique 8-bit address. The address of Port A is 00H, Port B is 01H and that
of Port C is 02H.

Delay calculation:
Time delay subroutines load a hexadecimal value as a count in a register or register pair.
The value is decremented until it reaches zero. For generation of time delay using a register pair,
Total T-states = 24N + 17 (N is the count)
Clock frequency of the system, f =3.172 MHz
Time for one T-state, T = 1/f = 320 ns
Time delay = Total T-states x Time for one T-state
= (24 N + 17) x 320 x 10-9
For a delay of 30 ms,
30 x 10-3 = (24 N + 17) x 320 x 10-9
N = 3905 = 0F41H
For a delay of 20 ms,
20 x 10-3 = (24 N + 17) x 320 x 10-9
N = 2603 = 0A2BH

PROGRAM 1: Sawtooth wave: Positive ramp


Memory Machine Label Mnemonics Comments
Address Code
8000 3E,80 MVI A, 80H Load the control word in the
accumulator.
OUT 03H Move the control word to the control
8002 D3,03 register
8004 3E,00 MVI A,00H Load 00H in the accumulator

8006 D3,00 LOOP: OUT 00H Send the value to Port A of 8255

8008 3C INR A Increment the accumulator content by


one
8009 C3,06,80 JMP LOOP Repeat

PROGRAM 2: Triangular wave


Memory Machine Label Mnemonics Comments
Address Code
8000 3E,80 MVI A, 80H Load the control word in the
accumulator.
OUT 03H Move the control word to the control
8002 D3,03 register
8004 3E,00 LOOP 3: MVI A,00H Load 00H in the accumulator

8006 D3,00 LOOP 1: OUT 00H Send the value to Port A of 8255

8008 3C INR A Increment the accumulator content by


one
8009 FE,FF CPI FFH Compare the accumulator content with
the maximum value, FFH
800B C2,06,80 JNZ LOOP1 Has the accumulator content reached
the maximum? If no, then continue
incrementing
800E D3,00 LOOP 2: OUT 00H Else send the value to Port A

8010 3D DCR A Decrement the accumulator content by


one
8011 C2,0E,80 JNZ LOOP2 Is the accumulator content zero? If no,
then continue decrementing
8014 C3,04,80 JMP LOOP3 If yes, then repeat for further waveform
cycles

PROGRAM III: Square wave with unequal on and off time period (T ON =30 ms and TOFF =
20 ms)
Memory Machine Label Mnemonics Comments
Address Code
8000 3E,80 MVI A, 80H Load the control word in the
accumulator.
OUT 03H Move the control word to the control
8002 D3,03 register
8004 3E,00 LOOP : MVI A,00H Load 00H in the accumulator

8006 D3,00 OUT 00H Send the value to Port A of 8255

8008 CD,50,80 CALL DELAY I Call delay subroutine I

800B 3E,FF MVI A, FFH Load FFH in the accumulator

800D D3,00 OUT 00H Send the value to Port A of 8255

800F CD,70,80 CALL DELAY II Call delay subroutine II

8012 C3,04,80 JMP LOOP Repeat for further cycles

DELAY I (TON = 30 ms)

8050 11,41,0F LXI D, 0F41H Load DE register pair with the delay
count
8053 1B LOOP 1: DCX D Decrement DE register pair

8054 7A MOV A, D Move the 8-bit content of D to the


accumulator
8055 B3 ORA E Logically OR the content of A with
E
8056 C2,53,80 JNZ LOOP 1 If the content of A is not equal to
zero, go to LOOP 1
8059 C9 RET Return to main program

DELAY II (TOFF= 20 ms)

8070 11,2B,0A LXI D, 0A2BH Load DE register pair with the delay
count
8073 1B LOOP 2: DCX D Decrement DE register pair

8074 7A MOV A, D Move the 8-bit content of D to the


accumulator
8075 B3 ORA E Logically OR the content of A with
E
8076 C2,73,80 JNZ LOOP 1 If the content of A is not equal to
zero, go to LOOP 2

8079 C9 RET Return to main program

Note: For square wave with equal delay (say, TON = TOFF = 30 ms), Delay I has to be called twice
in the above program.

PROCEDURE
Enter each program from memory location 8000H onwards. The assembler will assemble
the 8085 instructions in machine code. Connect the interfacing module cable from 8255-1
connector to the DAC module. Connect +12V, -12V and GND to the module. Execute the
programs and observe the corresponding output waveforms on channel 1 or channel 2 of the CRO
through the Xout and GND pins of the DAC.

RESULT
The following waveforms are generated using 8085 microprocessor kit and interfacing
devices:
(i) Sawtooth wave
(ii) Triangular wave
(iii) Square wave with equal and unequal delay.

You might also like