SIR C.R.REDDY COLLEGE OF ENGINEERING ELURU-534 007 · SIR C R Reddy College of Engineering 1...

68
SIR C R Reddy College of Engineering 1 Department of ECE SIR C.R.REDDY COLLEGE OF ENGINEERING ELURU-534 007 Department of Electronics and Communications MICROPROCESSOR & APPLICATIONS Lab Manual (EC-328) For III / IV B.E, II - Semester SIR C.R.REDDY COLLEGE OF ENGINEERING ELURU-534 007

Transcript of SIR C.R.REDDY COLLEGE OF ENGINEERING ELURU-534 007 · SIR C R Reddy College of Engineering 1...

SIR C R Reddy College of Engineering 1 Department of ECE

SIR C.R.REDDY COLLEGE OF ENGINEERING ELURU-534 007

Department of Electronics and Communications

MICROPROCESSOR & APPLICATIONS Lab Manual (EC-328)

For III / IV B.E, II - Semester

SIR C.R.REDDY COLLEGE OF ENGINEERING

ELURU-534 007

SIR C R Reddy College of Engineering 2 Department of ECE

MICROPROCESSOR & APPLICATIONS LAB

LIST OF EXPERIMENTS

1. a. Addition of two 8-bit numbers. b. Subtraction of two 8-bit numbers. 2. a. Addition of two 16-bit numbers. b. Subtraction of two 16-bit numbers. 3. a. Two digit BCD addition. b. Two digit BCD subtraction. 4. a. Program to test whether 5th bit is zero or not. b. Testing zero condition. c. Counting number of 1’s in a given data. 5. a. Sorting the data in Ascending order. b. Sorting the data in Descending order. 6. a. Multiplication of two 8-bit numbers using Successive Addition method.

b. Multiplication of two 8-bit numbers using Shift and Add method.

7. a. Conversion of data from BCD to Binary. b. Conversion of data from Binary to BCD. 8. Division of 16-bit number by 8-bit number. 9. Time Delay Loop for generation of Milliseconds. 10. a. Decimal counter (0-99).

b. Reset the decimal counter at a predefined number and store the count again. 11. Checking the given condition and store respective data in memory.

a. 00- Test the parity of the data at (x+1) and store DD for odd parity, EE for even parity at (y).

b. 01- Test the zero condition of the data and store 00 if zero and FF if not. c. 02- Test if the data is positive or negative

SIR C R Reddy College of Engineering 3 Department of ECE

ADDITION OF TWO 8-BIT NUMBERS

PROGRAM:

Write an assembly language program to add two binary numbers of 8-bit data

stored in memory locations 8C40H and 8C41H and store the result in 8C42H and

8C43H.

PROBLEM ANALYSIS:

To perform addition in 8085 one of the data should be in accumulator and another

data can be in any one of the general purpose register or in memory. After addition

the sum will be in accumulator. The sum of two 8-bit data can be either 8-bit (sum

only) or 9 bits (sum and carry). The accumulator can be accommodated only the

sum and if there is a carry, the 8085 will indicate by setting carry flag. Hence one of

the register is used to account for carry.

ALGORITHM:

1. Load the address of the data in H L reg. pair.

2. Clear C register.

3. Move the first data from memory to accumulator.

4. Increment the H L register pair (memory pointer).

5. Add the content as memory addressed by H L with accumulator.

6. Check for carry. If carry=1, go to step 7 or if carry =0, go to step 8.

7. Increment the C register.

8. Increment the H L pair and store the sum.

9. Increment the H L pair and store the carry.

10. Stop.

SIR C R Reddy College of Engineering 4 Department of ECE

SIR C R Reddy College of Engineering 5 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 21 40 8C LXI H, 8C40H ; Set pointer for data.

8C03H 0E 00 MVI C,00H ; Clear C Reg. to account for

carry

8C05H 7E MOV A,M ; Get first data in A reg.

8C06H 23 INX H ; Increment the pointer for

second data

8C07H 86 ADD M ; Add second data which is stored in

memory to A. sum in A Reg.

8C08H D2 0C 8C JNC L1 ; if CY=0, go to L1

8C0BH 0C INR C ; if CY=1 increment register C

8C0CH 23 L1 INX H ; increment the pointer to store the

sum in Memory

8C0DH 77 MOV M,A ; Store the sum in memory.

8C0EH 23 INX H ; Increment the pointer to store the

carry in Memory.

8C0FH 71 MOV M,C ; Store the carry in memory

8C10H 76 HLT ; Halt the program

SIR C R Reddy College of Engineering 6 Department of ECE

SUBTRACTION OF TWO 8 - BIT NUMBERS

PROGRAM: Write an assembly language program to subtract two numbers of 8-bit data stored

in memory locations 8C40H and 8C41H. Store the magnitude of the result in

8C42H. If the result is positive store 00 in 8C43H or if the result is negative store

01in 8C43H.

PROGRAM ANALYSIS:

To perform subtraction in 8085 one of the data should be in accumulator and

another data can be in anyone of the general purpose register or in memory. After

subtraction the result will be in accumulator. The 8085 performs 2’s complement

subtraction and then complements the carry. Therefore if the result is negative then

carry flag is set and accumulator will have 2’s complement of the result. Hence one

of the register is used to account for sign of the result. To get the magnitude of the

result again take 2’s complement of the result.

ALGORITHM:

1. Load the subtrahend (the data to be subtracted) from memory to accumulator

and move it to B- register.

2. Load the minuend from memory to accumulator.

3. Clear C register to account for sign of the result.

4. Subtract the content of B-register from the content of the accumulator.

5. Check for carry . if carry =1 go to step 6 or if carry=0 , go to step 7.

6. Increment C register , complement the accumulator and add 01H

7. store the difference in memory.

8. Move the content of C register (sign bit) to accumulator and store in memory.

9. Stop.

SIR C R Reddy College of Engineering 7 Department of ECE

SIR C R Reddy College of Engineering 8 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 3A 41 8C LDA 8C41H ; get subtrahend from 8C41H and

store in Acc

8C03H 47 MOV B,A ; move the content of the Acc. into B reg.

8C04H 3A 40 8C LDA 8C40H ; get the minuend in A - reg

8C07H 0E 00 MVI C,00H ; clear C register , to account for sign.

8C09H 90 SUB B ; get the difference in A register

8C0AH D2 11 8C JNC L1 ; if CY = 0 , then go to L1

8C0DH 0C INR C ; if CY = 1 then increment C register.

8C0EH 2F CMA ; get 2’s complement of difference

in A-reg

8C0FH C6 01 ADI 01 ; increment A register

8C11H 32 42 8C L1 STA 8C42H ; store the result in memory

8C14H 79 MOV A,C ; move the barrow to accumulator

8C15H 32 43 8C STA 8C43H ; store the sign bit in memory.

8C18H 76 HLT ; halt program

SIR C R Reddy College of Engineering 9 Department of ECE

16-BIT ADDITION

PROGRAM: Write an assembly language program to add two numbers of 16-bit data stored in

memory 8C40H, 8C41H and 8C42H, 8C43H. The data are stored such that LSB

first and then MSB and store the result from 8C44H to 8C46H

PROBLEM ANALYSIS:

The 16-bit addition can be performed in 8085 microprocessor either in terms of

8-bit addition or by using DAD instruction. In addition using DAD instruction,

one of the data should be in H L pair and another data can be another register

pair. After addition the sum will be in H L register pair. If there is a carry in

addition then that is indicated by setting carry flag. Hence one the register is used

to account for carry.

ALGORITHM:

1 load the first data in H L register pair.

2. Move the first data to D E register pair.

3. Load the second data in H L register pair.

4. Clear A register for carry.

5. Add the content of D E pair to H L pair.

6. Check for carry. If carry =1, go to step 7 or if carry=0 go to step 8.

7. Increment carry register (A) to account for carry.

8. Store the sum and carry in memory.

9. Stop.

SIR C R Reddy College of Engineering 10 Department of ECE

SIR C R Reddy College of Engineering 11 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 2A 40 8C LHLD 8C40H ; get first data in HL reg. pair. 8C03H EB XCHG ; store first data in DE reg. pair 8C04H 2A 42 8C LHLD 8C42H ; get second data in HL reg. pair 8C07H AF XRA A ; clear A register for carry 8C08H 19 DAD D ; get the sum in HL pair. 8C09H D2 0D 8C JNC L1 ; if CY=0 go to L1 8C0CH 3C INR A ; if CY=1, increment A reg. 8C0DH 22 44 8C L1 SHLD 8C44H ; store the sum in memory. 8C10H 32 46 8C STA 8C46H ; store the carry in memory.

8C13H 76 HLT ; halt the program

SIR C R Reddy College of Engineering 12 Department of ECE

16-BIT SUBTRACTION

PROGRAM:

Write an assembly language program to subtract two numbers of 16-bit data stored

in memory from 8C40H to 8C43H. The data are stored such that LSB first and then

MSB. Store the result in 8C44H and 8C45H.

PROBLEM ANALYSIS:

The 16-bit subtraction is performed in terms of 8-bit subtraction. First LSB’s of the

data are subtracted and the result is stored in memory. Then MSB’s of the data are

subtracted along with borrow in the previous subtraction and the result is stored in

memory.

ALGORITHM:

1. Load the low byte of subtrahend in accumulator from memory and move is to

B-register.

2. Load the low byte of minuend in accumulator from memory.

3. Subtract the content of B-register from the content of accumulator.

4. Store the low byte of result in memory.

5. Load the high byte of subtrahend in accumulator from memory and move it to

B-register.

6. Load the high byte of minuend in accumulator from memory.

7. Subtract the content of B-register and the carry from the content of

accumulator.

8. Store high byte of result in memory.

9. Stop the program.

SIR C R Reddy College of Engineering 13 Department of ECE

SIR C R Reddy College of Engineering 14 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE MNEMONIC COMMENT LOCATION CODE 8C00H 3A 42 8C LDA 8C42H ; get the LSB of subtrahend from 8C42H and store in Acc 8C03H 47 MOV B, A ; Move the LSB of subtrahend

to B-register 8C04H 3A 40 8C LDA 8C40H ; get the LSB of minuend in

A-register 8C07H 90 SUB B ; get the difference of LSB’s in

A-register 8C08H 32 44 8C STA 8C44H ; store the result in memory. 8C0BH 3A 43 8C LDA 8C43H ; get the MSB of subtrahend from 8C43H and store in Acc 8C0EH 47 MOV B, A ; Move the MSB of subtrahend to

B-register. 8C0FH 3A 41 8C LDA 8C41H ; get the MSB of minuend in

A-register. 8C12H 98 SBB B ; get the difference of MSB’s in

A-register. 8C13H 32 45 8C STA 8C45H ; store the result. 8C16H 76 HLT ; halt the program

SIR C R Reddy College of Engineering 15 Department of ECE

ASSEMBLY LANGUAGE PROGRAM:

MEMORY MACHINE LABEL MNEMONIC COMMENT

LOCATION CODE

8COOH 3A 42 8C LDA 8C42H ; get the LSB of subtrahend from

8C42H and store in Acc

8CO3H 03 MOV B, A ; Move the LSB of subtrahend

to B-register

8CO4H 3A 40 8C LDA 8C40H ; get the LSB of minuend in

A-register

8CO7H 0E 00 MVI C, 00H ; Move immediately 00H to C-reg.

8CO9H 90 SUB B ; Subtract B from A

8COAH 57 MOV D, A ; Move the content of A to D-reg

8COBH 3A 43 8C LDA 8C43H ; get the MSB of subtrahend from

8C43H and store in A

8COEH 47 MOV B,A ; Move the MSB of subtrahend

to B-register

8COFH 3A 41 8C LDA 8C41H ; get the MSB of minuend in

A-register

8C12H 98 SBB D ; Subtract B from A with borrow

8C13H D2 25 8C JNC AHEAD ; If CY=0, go to AHEAD

8C16H 2F CMA ; If CY=1, complement A

8C17H 67 MOV H, A ; Move the content of A to H-reg

8C18H 7A MOV A,D ; Move the content of D to A-reg

8C19H 2F CMA ; complement A

8C1AH 6F MOV L,A ; Move the content of A to L-reg

8C1BH 23 INX H ; Increment HL Reg pair

8C1CH 0C INX C ; Increment BC Reg pair

8C1DH 79 MOV A,C ; Move the content of C to A-reg

8C1EH 32 46 8C STA 8C46H ; store the result

8C21H 22 44 8C SHLD 8C44H ; store the result

8C24H 76 HLT ; Stop

8C25H 32 45 8C AHEAD STA 8C45H ; store the result

8C28H 7A MOV A, D ; Move the content of D to A-reg

8C29H 32 44 8C STA 8C44H ; store the result

8C2CH 79 MOV A, C ; Move the content of C to A-reg

8C2DH 32 46 8C STA 8C46H ; store the result

8C30H 76 HLT ; Stop

SIR C R Reddy College of Engineering 16 Department of ECE

TWO DIGIT BCD ADDITION

PROGRAM:

Write an assembly language program to add two numbers of two digit (single

precession) BCD data stored memory locations 8C40H and 8C41H. Store the result

in 8C42H and 8C43H.

PROBLEM ANALYSIS:

The 8085 microprocessor will perform only binary addition. Hence for BCD

addition, the binary addition of BCD data is performed and then the sum is

corrected to get result in BCD. After binary addition the following correction should

be made to get the result in BCD.

1. if the sum of lower nibble exceeds 9 or if there is an auxiliary carry then

06 is added to lower nibble.

2. if the sum of upper nibble exceeds 9 or if there is carry then 06 is added to

upper nibble.

The above correction is taken care by DAA instruction. Therefore after binary

addition execute DAA instruction to do the above correction in the sum.

ALGORITHM:

1. Load the first data in accumulator and move it to B-register.

2. Load the second data in accumulator.

3. Clear the C register for storing carry.

4. Add the content of B-register to accumulator.

5. Execute DAA instruction.

6. Check for carry. If carry=1, go to step 7 or if carry=0, go to step 8.

7. Increment C register to account for carry.

8. Store the sum in memory.

9. Move the carry (content of C register) to accumulator and store in memory.

10. Stop.

SIR C R Reddy College of Engineering 17 Department of ECE

SIR C R Reddy College of Engineering 18 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 3A 40 8C LDA 8C40H ; get first data in accumulator. 8C03H 47 MOV B, A ; transfer accumulator data

to B-register. 8C04H 3A 41 8C LDA 8C41H ; get second data in A-register. 8C07H OE OO MVI C, 00H ; clear C register for accounting

carry. 8C09H 80 ADD B ; add the content of B-register to

A-register. 8C0AH 27 DAA ; get the sum of BCD data in

A- reg. 8C0BH D2 0E 8C JNC L1 ; if CY=0, go to L1. 8COEH 0C INR C ; if CY=1, increment C- reg. 8C0FH 32 42 8C L1 STA 8C42H ; store the sum in memory. 8C12H 79 MOV A, C ; move the carry to A- reg. 8C13H 32 43 8C STA 8C42H ; store the carry in memory. 8C16H 76 HLT ; halt the program.

SIR C R Reddy College of Engineering 19 Department of ECE

TWO DIGIT BCD SUBTRACTION

PROGRAM:

Write an assembly language program to subtract BCD numbers of 2 digit BCD data

stored in memory 8C40H and 8C41H. store the result in 8C42H.

PROBLEM ANALYSIS:

The 8085 microprocessor will perform only binary subtraction. Hence for BCD

subtraction 10’s complement subtraction is performed. First the 10’s complement of

the subtrahend is obtained and then added to minuend. The DAA instruction is

executed to get the result in BCD.

ALGORITHM:

1. Load the subtrahend in A-register and move to B-register.

2. Move 99 to A-register and subtract the content of B-register from A-register.

3. Increment the A-register.

4. Move the content of A-register to B-register.

5. Load the minuend in A-register.

6. Add the content of B-register to a A-register.

7. Execute DAA instruction.

8. Store the result in memory.

9. Stop.

SIR C R Reddy College of Engineering 20 Department of ECE

SIR C R Reddy College of Engineering 21 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE MNEMONIC COMMENT LOCATION CODE 8COOH 3A 41 8C LDA 8C41H ; get the subtrahend in to

accumulator. 8CO3H 47 MOV B,A ; move the data into B-register from

A-reg. 8CO4H 3E 99 MVI A,99 ; move the 99 to A-reg. 8C06H 90 SUB B ; subtract the subtrahend from 99. 8C07H 3C INR A ; 10’s complement of subtrahend. 8C08H 47 MOV B,A ; store the 10’s complement

of subtrahend in B

8CO9H 3A 40 8C LDA 8C40H ; get the minuend in A-register 8COCH 80 ADD B ; Get the BCD sum of minuend and

10’complemnt of subtrahend. 8CODH 27 DAA ; the sum is the difference

between given BCD data. 8COEH 32 42 8C STA 8C42H ; store the result in memory. 8C11H 76 HLT ; halt the program.

SIR C R Reddy College of Engineering 22 Department of ECE

SORTING OF DATA IN ASCENDING ORDER.

PROGRAM:

Write an assembly language program to sort an array of data in ascending order

and find the largest number and display it in the data field. The array is stored in

memory starting from 8C40H. The first element of the array gives the count value

for the number of elements in the array.

PROBLEM ANALYSIS: The algorithm for bubble sorting is given below. In bubble sorting of N-data,

(N-1) comparisons are carried by taking two consecutive data at a time. After each

comparison, the data are rearranged such that smallest among the two is in first

memory location and largest in the next memory location. When we perform (N-1)

comparisons as mentioned above, for (N-1) times then the array consisting of N-

data will be sorted in the ascending order.

ALGORITHM:

1. Load the count value from memory to A-reg. and save it in B-reg.

2. Decrement B-reg . (B is a count for N-1 repetitions)

3. Set H L pair as data address pointer.

4. Set C-register as counter for (N-1) comparisons.

5. Load a data of the array in accumulator using the data address pointer.

6. Increment the H L pair (data address pointer).

7. Compare the data pointed by H L with accumulator.

8. if carry flag is set (if the content of the accumulator is smaller than memory)

then go to step 10, otherwise go to next step.

9. Exchange the content of memory pointed by H L and the accumulator.

10. Decrement C-register. if zero flag is reset go to the step 6 otherwise go to next

step.

11. Decrement B-register. If zero flag is reset go to step 3 otherwise go to next

step.

12. Load the largest value from memory into accumulator.

13. Store the content of accumulator in memory location 8FF1H.

14. Call subroutine to display the content of memory location 8FF1H into the data

field.

15. Stop.

SIR C R Reddy College of Engineering 23 Department of ECE

SIR C R Reddy College of Engineering 24 Department of ECE

ASSEMBLY LANGUAGE PROGRAM:

MEMORY MACHINE LABEL MNEMONIC COMMENT

LOCATION CODE

8COOH 3A 40 8C LDA 8C4OH ; load the count value in A-reg.

8CO3H 47 MOV B,A ; set counter for (N-1)repetitions of

8CO4H 05 DCR B N-1 comparisons.

8CO5H 21 40 8C L2 LXI H,8C4OH ; set pointer for array.

8CO8H 4E MOV C,M ; set counter for (N-1) comparisons.

8CO9H OD DCR C ;

8COAH 23 INX H ; increment pointer

8COBH 7E L1 MOV A,M ; get one data of array in A-reg.

8COCH 23 INX H ; increment pointer.

8CODH BE CMP M ; compare next data with A-reg.

8COEH DA 16 8C JC L3 ; if content of A is less than

memory then go to L3

8C11H 56 MOV D,M ; if the content of A is greater than

8C12H 77 MOV M,A the content of memory then exchange

8C13H 2B DCX H the content of memory pointed by H L

8C14H 72 MOV M,D and previous location.

8C15H 23 INX H ;

8C16H OD L3 DCR C ; decrement C-register.

8C17H C2 0B 8C JNZ L1 ; repeat comparisons until C reg.

count is zero.

8C1AH 05 DCR B ; decrement B-register.

8C1BH C2 05 8C JNZ L2 ; repeat until B count is zero.

8C1EH 7E MOV A,M ; get the largest number into

accumulator.

8C1FH 32 F1 8F STA 8FF1H ; store the content of accumulator

in memory location 8FF1H.

8C22H CD 4C 04 CALL 044CH ; call subroutine to display the

content of the memory location

8FF1H in data field.

8C25H 76 HLT ; halt the program.

SIR C R Reddy College of Engineering 25 Department of ECE

SORTING OF DATA IN DESCENDING ORDER.

PROGRAM:

Write an assembly language program to sort an array of data in descending order

and find the smallest number and display it in the data field. The array is stored in

memory starting from 8C40H. The first element of the array gives the count value

for the number of elements in the array.

PROBLEM ANALYSIS:

The algorithm for bubble sorting is given below. In bubble sorting of N-data , (N-1)

comparisons are carried by taking two consecutive data at a time. After each

comparison, the data are rearranged such that largest among the two is in first

memory location and smallest in the next memory location. When we perform (N-1)

comparisons as mentioned above, for N times then the array consisting of N-data

will be sorted in the descending order.

ALGORITHM:

1. Load the count value from memory to A-reg. and save it in B-reg.

2. Decrement B-reg (B is a count for N-1 repetitions).

3. Set H L pair as data address pointer.

4. Set C-register as counter for (N-1) comparisons.

5. Load a data of the array in accumulator using the data address pointer.

6. Increment the H L pair (data address pointer).

7. Compare the data pointed by H L with accumulator.

8. If carry flag is reset (if the content of the accumulator is larger than memory)

then go to step 10, otherwise go to next step.

9. Exchange the content of memory pointed by H L and the accumulator.

10. Decrement C-register. if zero flag is reset go to the step 6 otherwise go to next

step.

11. Decrement B-register. If zero flag is reset go to step 3 otherwise go to next

step.

12. Load the smallest value from memory into accumulator.

13. Store the content of accumulator in memory location 8FF1H.

14. Call subroutine to display the content of memory location 8FF1H into the

data field.

15. Stop.

SIR C R Reddy College of Engineering 26 Department of ECE

SIR C R Reddy College of Engineering 27 Department of ECE

ASSEMBLY LANGUAGE PROGRAM:

MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8COOH 3A 40 8C LDA 8C4OH ; load the count value in

A-reg. 8CO3H 47 MOV B,A ; set counter for

(N-1) repetitions of 8CO4H 05 DCR B N-1 comparisons. 8CO5H 21 40 8C L2 LXI H,8C4OH ; set pointer for array. 8CO8H 4E MOV C,M ; set counter for

(N-1) comparisons. 8CO9H OD DCR C ; 8COAH 23 INX H ; increment pointer 8COBH 7E L1 MOV A,M ; get one data of array in

A-reg. 8COCH 23 INX H ; increment pointer. 8CODH BE CMP M ; compare next data with

A-reg. 8COEH DA 16 8C JNC L3 ; if content of A is less than

memory then go to L3 8C11H 56 MOV D,M ; if the content of A is greater than the content of memory then exchange the content of memory pointed by H L and previous location. 8C12H 77 MOV M, A 8C13H 2B DCX H 8C14H 72 MOV M, D 8C15H 23 INX H 8C16H OD L3 DCR C ; decrement C-register. 8C17H C2 0B 8C JNZ L1 ; repeat comparisons until

C reg. count is zero. 8C1AH 05 DCR B ; decrement B -register. 8C1BH C2 05 8C JNZ L2 ; repeat until B count is zero. 8C1EH 7E MOV A,M ; get the smallest number

into accumulator. 8C1FH 32 F1 8F STA 8FF1H ; store the content of

accumulator in memory location 8FF1H.

8C22H CD 4C 04 CALL 044CH ; call subroutine to display the content of the memory location 8FF1H in data field.

8C25H 76 HLT ; halt the program

SIR C R Reddy College of Engineering 28 Department of ECE

MULTIPLICATION OF TWO 8-BIT NUMBER (SHIFT and ADD METHOD)

PROBLEM: Write an assembly language program to multiply two numbers of 8 –bit data stored

in memory 8C4OH and 8C42H. store the product in 8C43H and 8C44H.

PROBLEM ANALYSIS: In this program multiplication is performed by using shifting and adding method. In

binary multiplication, when a multiplicand is multiplied by 1 the product is equal to

the multiplicand. When a multiplicand is multiplied by 0 the product is 0. The

procedure for multiplication is that first the multiplicand is multiplied by the LSB of

the multiplier and the partial product is stored and shifted right. Again the

multiplicand is multiplied by the 2nd bit and the result is added to the previous

shifted partial product. The procedure is repeated. If the bit of the multiplier is 1

the multiplicand is added to the previous partial product. In case of 0 bit there is

nothing to be added, to the partial product but it will be simply shifted right by 1

bit. In case of binary multiplication by 8085, if the partial product is shifted left

instead of right, and we take bits of multiplier from MSB side instead of LSB side,

the final product will remain in the same.

ALGORITHM:

1. Load the multiplicand in H L register pair.

2. Move the multiplicand to D E register pair.

3. Load the multiplier in accumulator from memory.

4. Clear H L register pair.

5. Move 08H to a register C.

6. Shift the content of H L register pair left by one bit.

7. Rotate the content of accumulator left by 1 bit.

8. Check for carry, if CY=1 go to step 9 or if CY=0 go to step 10.

9. Add the content of D E pair to the content of H L pair.

10. Decrement C register.

11. Check whether count has reached zero. If ZF=0 repeat step 6 through 11.

if ZF=1 go to next step.

12. Store the product in memory (content of H L pair)

13. Stop.

SIR C R Reddy College of Engineering 29 Department of ECE

SIR C R Reddy College of Engineering 30 Department of ECE

ASSEMBLY LANGUAGE PROGRAM:

MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8COOH 2A 4O 8C LHLD 8C4OH ; get multiplicand in H L pair. 8CO3H EB XCHG ; get multiplicand in D E pair. 8CO4H 3A 42 8C LDA 8C42H ; get multiplier in accumulator 8CO7H OE O8 MVI C, O8H ; count O8 in register C. 8CO9H 21 OO OO LXI H,OOOOH ; initial value of product OOOOH in H L pair 8COCH 29 L1 DAD H ; shift partial product left by 1 bit. 8CODH 17 RAL ; rotate multiplier left by 1 bit. 8C0EH D2 12 8C JNC L2 ; if multiplier bit is O go to L2. 8C11H 19 DAD D ; if multiplier bit is 1

Product = product + Multiplicand

8C12H OD L2 DCR C ; decrement count. 8C13H C2 OC 8C JNZ L1 ; if ZF=1 go to next step.

; If ZF=0 go to L1 8C16H 22 43 8C SHLD 8C43H ; store the result. 8C19H 76 HLT ; halt the program .

SIR C R Reddy College of Engineering 31 Department of ECE

MULTIPLICATION OF TWO 8-BIT NUMBER (SUCCESSIVE ADDITION METHOD)

PROBLEM: Write an assembly language program to multiply two numbers of 8 –bit data stored

in memory 8C4OH and 8C41H. store the product in 8C42H and 8C43H.

PROBLEM ANALYSIS:

In this method multiplication is performed as repeated additions. The initial value

of sum is assumed as zero. One of the data is used as count (N) . For number of

additions to be performed. Another data is added to the sum N times where N is the

count. The result of the product of two 8-bit data may be 16-bit data. Hence

another register is used to account for over flow.

ALGORITHM:

1. Load the address of the first data in H L pair.

2. Clear C register for over flow.

3. Clear the accumulator.

4. Move the first data to B register.

5. Increment the pointer.

6. Move the second data to D register from memory.

7. Add the content of D-register to accumulator.

8. Check for carry. If CY=1 go to step 9 or if CY=0 go to step10.

9. Increment C register.

10. Decrement B register.

11. Check whether count has reached zero. If ZF=0 repeat steps 7 to 11. if ZF=1

got to next step.

12. Increment the pointer and store the LSB of the product in memory.

13. Increment the pointer and store the MSB of the product in memory.

14. Stop.

SIR C R Reddy College of Engineering 32 Department of ECE

SIR C R Reddy College of Engineering 33 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8COOH 21 40 8C LXI H, 8C40H ; set pointer for data.

8CO3H OE OO MVI C, OOH ; clear C register to account

for over flow

8CO5H AF XRA A ; clear accumulator

(initial sum=0).

8CO6H 46 MOV B,M ; get first data in B register.

8C07H 23 INX H ; increment pointer.

8CO8H 56 MOV D,M ; get second data in D register.

8CO9H 82 L1 ADD D ; add the content D register to

accumulator

8COAH O2 OE 8C JNC L2 ; if CY=0, go to L2

8CODH OC INR C ; if CY=1 increment C register

8COEH O5 L2 DCR B ; if CY=0 decrement B register

8COFH C2 O9 8C JNZ L1 ; repeat addition until ZF=1.

8C12H 23 INX H ; Increment HL Reg pair

8C13H 77 MOV M,A ; store LSB of product

in memory.

8C14H 23 INX H ; Increment HL Reg pair

8C15H 71 MOV M,C ; store MSB of product in

memory.

8C16H 76 HLT ; halt the program.

SIR C R Reddy College of Engineering 34 Department of ECE

CONVERSION OF BCD NUMBER TO BINARY NUMBER

PROBLEM: Conversion of two digit BCD number to binary number. A two digit BCD number is

stored at data memory location 8C4OH. Write an assembly language program to

convert the number in to binary and display the result in data field.

PROBLEM ANALYSIS: The two digit BCD data will have units digit and 10’s digit. The 10’s digit (upper

nibble) is multiplied by OAH and the product is added to units digit (lower nibble).

The microprocessor performs binary arithmetic and so the result will be in binary.

ALGORITHM: 1. Get the BCD data in A register and save in E register.

2. Mask the lower nibble of the BCD data in A register.

3. Rotate the upper nibble to lower nibble position and save in C register.

4. Clear the accumulator.

5. Move 0AH to B register.

6. Add C register to A register content.

7. Decrement B register. if ZF=0 go to step 6. if ZF=1 go to next step.

8. Save the product in B register.

9. Get the BCD data in A register from E register and mask the upper nibble.

10. Add the units A register digit to product B register.

11. Store the binary value in memory location 8FF1H

12. Call monitor subroutine to display the content of memory location 8FF1H in the

data field

13. Stop.

SIR C R Reddy College of Engineering 35 Department of ECE

SIR C R Reddy College of Engineering 36 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8COOH 3A 40 8C LDA 8C40H ; get data in A register.

8CO3H 5E MOV E,A ; and store in E register.

8CO4H E6 FO ANI FOH ; mask the lower nibble

8CO6H O7 RLC ; rotate the upper nibble to

lower nibble position

8CO7H O7 RLC ;

8CO8H O7 RLC ;

8CO9H O7 RLC ;

8COAH O6 OA MVI B.OAH ; get OAH in B register

8COCH 4F MOV C,A ; save the content

of accumulator in C Register

8CODH AF XRA A ; clear accumulator.

8COEH 81 L1 ADD C ; get the product of 10’s

digit multiplied

by OAH in A register

8COFH O5 DCR B ; Decrement B Reg

8C1OH C2 OE 8C JNZ L1 ; If ZF=0, go to L1

8C13H 47 MOV B,A ; save the product in B register

8C14H 7B MOV A,E ;

8C15H E6 OF ANI OFH ; mask the upper nibble

8C17H 8O ADD B ; get the sum of units digit

and product in A register

8C18H 32 F1 8F STA 8FF1H ; save the content of A register

in memory location 8FF1H

8C1BH CD 4C O4 CALL 044CH ; call subroutine to display the

content of memory location in

data field

8C1EH 76 HLT ; stop.

SIR C R Reddy College of Engineering 37 Department of ECE

CONVERSION OF 8 BIT BINARY NUMBER TO BCD NUMBER

PROBLEM: Write an assembly language program to convert an 8-bit binary number to BCD.

The binary number is stored in memory location 8C4OH. Store the 100’s digit in

8C51H and the 10’s and 1’s (digits) in 8C50H.

PROGRAM ANALYSIS: The maximum value of 8-bit binary is FFH. FFH =255 10. Hence the maximum size

of the data will have hundreds, 10’s and units. The algorithm is given below uses

two counters to count 100’s and 10’s. Initially counters are cleared first it subtracts

all 100’s from data. For each subtraction 100’s counter is incremented by 1. then it

subtracts all 10’s . for each subtraction 10’s register is incremented by 1. The

remaining will be units. The ten’s and units are combined to form two digit BCD.

ALGORITHM:

1. Clear D and E register to account for 100’s and 10’s .

2. Load the binary data in A register.

3. Compare A register with 64H . if CY=1 , go to step 7. otherwise go to next

step.

4. Subtract 64H from A register.

5. Increment E register.

6. Go to step 3.

7. Compare the A register with OAH. If CY=1 go to step 1 otherwise go to next

step.

8. Subtract OAH from A register.

9. Increment D register.

10. Go to step 7.

11. Combine the units and tens to form 8 bit result.

12. Save the units, tens and hundreds in memory

13. Stop.

SIR C R Reddy College of Engineering 38 Department of ECE

SIR C R Reddy College of Engineering 39 Department of ECE

ASSEMBLY LANGUAGE PROGRAM:

MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE

8COOH 3A 40 8C LDA 8C40H ;get the binary data in A

register

8CO3H 1E OO MVI E,OOH ;clear E register for 100’s

8CO 5H 53 MOV D,E ;clear D register for 10’s

8CO6H FE 64 L2 CPI 64H ;compare whether data is

less than 64H

8CO8H DA 11 8C JC L1 ;if content of A less than 64H

go to L1

8COBH D6 64 SUI 64H ;subtract all the 100’s from

the data. and for each

subtraction increment E

repeat the process until data

less than 64H

8CODH 1C INR E

8COEH C3 O6 8C JMP L2

8C11H FE OA L1 CPI OAH ;compare whether data is

less than OAH

8C13H DA 1C 8C JC L3 ;if CY = 1 go to L3

8C16H D6 OA SUI OAH ; subtract all the 10 `s from

the data and for each

subtraction increment the 10`s

registers.

8C18H 14 INR D

8C19H C3 11 8C JMP L1

8C1CH 32 52 8C L3 STA 8C52H ;store the units value in 8C52H.

8C1FH 7B MOV A,E ;move the no of 100’s into

Accumulator

8C20H 32 51 8C STA 8C51H ;store the no of 100’s to 8C51H

8C23H 7A MOV A,D ;move no of 10’s to

accumulator.

8C24H 32 50 8C STA 8C50H ;store the no. of 10’s in 8C50H.

8C27H 76 HLT ;halt the program

SIR C R Reddy College of Engineering 40 Department of ECE

CONVERSION OF BINARY NUMBER (<64H) INTO BCD NUMBER

AIM: Convert a binary number in memory location8C40H to two BCD digits in memory

location 8C41H and 8C42H (MSB in 8C41H). The number in memory location 8C40H is

unsigned and less than 64H.

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8COOH 3A 40 8C LDA 8C40H ; Get the data from 8C40H

location into A Register

8CO3H 1E 00 MVI E, 00H ; Move immediately 00H into

E Register

8CO5H FE 0A L2 CPI 0AH ; Compare

8CO7H DA 10 8C JC L1 ; If CY=1 go to L1

8C0AH D6 0A SUI 0AH ; Subtract immediately 0AH

content from A Register

8COCH 1C INR E ; Increment E Register

8CODH C3 05 8C JMP L2 ; Jump unconditional to L2

8C10H 32 42 8C L1 STA 8C42H ; Store the Accumulator

content into the memory

location 8C42H

8C13H 7B MOV A, E ; Move E Reg content into

the Accumulator

8C14H 32 41 8C STA 8C41H ; Store the Accumulator

content into the memory

location 8C41H

8C17H 76 HLT ; Stop

SIR C R Reddy College of Engineering 41 Department of ECE

DIVISION OF 16 BIT NUMBER BY 8 BIT NUMBER

PROGRAM: Division of 16 bit number by 8 – bit number write an assembly language program

to divide a 16 – bit unsigned binary numbers stored in memory locations 8C40 H

and 8C41 H by the 8 – bit unsigned binary number stored in memory location 8C42

H, store the quotient in memory location 8C43 H and remainder in memory location

8C44 H.

PROBLEM ANALYSIS: The processors perform division by trial subtraction. The divisor is subtracted from

the 8 MSB`s of dividend. If there is no barrow, the bit of the quotient is set to 1,

otherwise 0 the line up the dividend and divisor the dividend is shifted left by 1 bit

before each trial of subtraction. The dividend and quotient share a 16 – bit register

due to shift of dividend one bit of register falls vacant in each step. The quotient is

shifted in vacant bit positions.

ALGORITHM : 1: Load the dividend in HL register pair

2: Load the divisor accumulator from memory

3: move the content of accumulator into A register

4: move 08 to register C

5: shift the content of H,L register pair left by 1 bit

6: subtract content of B register from content of accumulator

7: check for carry .If CY=0 go to step 8 or If CY =1 go to step 9

8: move the content of accumulator in to H,L pair

9: increment L register by 1

10: decrement C register 1

11: check whether count has reached zero. If ZF =1 go to next step. Or If ZF=0

repeat step 5 through 12

12: store the remainder in 8c44H and Quotient in 8c43H

13: Stop

SIR C R Reddy College of Engineering 42 Department of ECE

SIR C R Reddy College of Engineering 43 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 2A 40 8C LHLD 8C40H ; get divided in to HL pair

8C03H 3A 42 8C LDA 8C42H ; get divisor from 8C42H

8C06H 47 MOV B,A ; get divisor in register B

8C07H OE 08 MVI C,08 ; Count = 08 in register C

8C09H 29 L1 DAD H ; shift dividend and quotient left

By one bit

8C0AH 7C MOV A,H ; most significant bits of dividend

in accumulator

8C0BH 90 SUB B ; subtract divisor from MSB `s

of dividend

8C0CH DA 11 8C JC L2 ; is MSB part of divider > divisor?

No go to ahead

8C0FH 67 MOV H,A ; MSB `s of dividend in register H

8C10H 2C INR L ; Add to quotient

8C11H OD L2 DCR C ; decrement count

8C12H C2 09 8C JNZ L1 ; is count = 0? if no jump to loop

8C15H 22 43 8C SHLD 8C43H ; store quotient in 8C43H and reminder

In 8C44H

8C18H 76 HLT ; stop

SIR C R Reddy College of Engineering 44 Department of ECE

PROGRAM TO TEST WHETHER 5TH BIT IS 0 or NOT

PROGRAM: Assume that first byte of data is stored at data memory location 8C40H. Write a

program which tests bit 5 of 8C40H. Write FFH in 8C41H; if bit 5=0 and write 00 at

the same location if bit-5 =1

PROBLEM ANALYSIS:

To perform the above function, load some data in to accumulator and move data

20H to register B. Then contents of B register are ANDed with contents of

accumulator clear A register check for the condition .If ZF =0 go to another step

ahead. If ZF =1, complement accumulator contents then store the result in specified

memory location.

ALGORITHM:

1: load data in to accumulator

2: move data 20h in to register B

3: content of B register is logically ANDed with accumulator

4: clear A register

5: check whether result is zero. IF ZF =O go to step 7

6: If ZF= 1 complement accumulator

7: store the accumulator contents in memory location 8C41H

8: stop

SIR C R Reddy College of Engineering 45 Department of ECE

SIR C R Reddy College of Engineering 46 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 3A 40 8C LDA 8C40H ; Get the data from 8C40H

location into A Register

8C03H E6 20 ANI 20H ; Logical AND immediately

between content of

Accumulator with 20H

8CO5H 3E 00 MVI A, 00H ; Move immediately 00H into

the Accumulator

8C07H C2 OB 8C JNZ AHEAD ; If ZF= 0 go to AHEAD

8C0AH 2F CMA ; If ZF= 1, Complement A

8C0BH 32 41 8C AHEAD STA 8C41H ; Store the Accumulator

content into the memory

location 8C41H

8C0EH 76 HLT ; Stop

SIR C R Reddy College of Engineering 47 Department of ECE

TESTING ZERO CONDITION

PROGRAM: Write a program which tests the zero condition of a data byte specified at data

memory location 8C40H. I f it zero 00 should be stored at 8C41H location. If non

zero ‘FF’ should be stored at the same location

PROBLEM ANALYSIS: To perform the above operation load some data in to accumulator and perform the

logical AND operation. Move data FFH in to accumulator check the condition I f

ZF=0 go to ahead condition or If ZF=1 complement the accumulator contents and

store the result in memory.

ALGORITHM: 1: load data into accumulator

2: perform logical AND operation with accumulator contents

3: move data FFH in to accumulator

4: check the condition If ZF =0 go to step 6

5: If ZF =1 complement the accumulator

6: store the result in memory

7: stop

SIR C R Reddy College of Engineering 48 Department of ECE

SIR C R Reddy College of Engineering 49 Department of ECE

ASSEMBLY LANGUAGE PROGRAM:

MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 3A 40 8C LDA 8C40H ; Get the data from 8C40H

location into A Register

8C03H A7 ANA A ; Logical AND between

content of Accumulator

with itself

8CO4H 3E FF MVI A, FFH ; Move immediately FFH into

the Accumulator

8C06H C2 OA 8C JNZ AHEAD ; If ZF= 0 go to AHEAD

8C09H 2F CMA ; If ZF= 1, Complement A

8C0AH 32 41 8C AHEAD STA8C41H ; Store the Accumulator

content into the memory

location 8C41H

8C0DH 76 HLT ; Stop

SIR C R Reddy College of Engineering 50 Department of ECE

COUNTING NUMBER OF 1’S IN A GIVEN DATA

PROGRAM: A binary number is stored at data memory location 8C40H compute the number of

its logical 1’s and store the result at 8C41H

PROBLEM ANALYSIS:

To do the given task, first load some data in to accumulator. Move data 08H to B

register and then clear the c register for account of counting . perform shift left

operation . the content of accumulator is shifted to left by on bit and then

condition is checked . If CY =1 increment C register or I f CY =0, go to another step

specified . In this decrement B register move the content of c to A register and then

store the result in 8C41H

ALGORITHM: 1: load data in to accumulator

2: clear C register

3: move data 08H to B register to account for count

4: rotate accumulator contents left by one bit

5: check, whether carry is set or not. If CY =1go to step 6 or if CY = 0 go to step 7

6: increment C register

7: decrement B register and check whether count has reached zero . If ZF repeat

next or if ZF =0 repeat step 4 through step 8 .

8: move data from C register to A register

9: store the result in memory

10: stop.

SIR C R Reddy College of Engineering 51 Department of ECE

SIR C R Reddy College of Engineering 52 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE

8C00H 3A 40 8C LDA 8C40H ; Get the data from 8C40H

location into A Register

8C03H 0E 00 MVI C,00H ; Move immediately 00H into

C Register

8CO5H 06 08 MVI B, 08H ; Move immediately 08H into

C Register

8C07H 17 LI RAL ; Rotate Accumulator left

(SHIFT)

8C08H D2 0C 8C JNC AHEAD ; If CY= 0, go to AHEAD

8C0BH 0C INR C ; If CY= 1, increment C Reg

8C0CH 05 AHEAD DCR B ; Decrement B Reg

8C0DH C2 O7 8C JNZ L1 ; If ZF= 0, go to L1

8C10H 79 MOV A,C ; If ZF=1, move the content

of C Reg into A Reg

8C11H 32 41 8C STA 8C41H ; Store the Accumulator

content into the memory

location 8C41H

8C14H 76 HLT ; Stop

SIR C R Reddy College of Engineering 53 Department of ECE

DECIMAL COUNTER

PROGRAM (A): Write a program for decimal counter (00 to 99) and displaying the count in the data

field using the corresponding monitor subroutines.

PROBLEM ANALYSIS: To design a counter is decimal counter from 00 to 99. Here we have to convert the

hexadecimal counter to decimal count. In this the process of counting is done using

a time delay process. In this counter we require numbers from 00 to 99. The

hexadecimal number is converted in to decimal number by using DAA instruction.

Since we require only number 00 to 99. We compare the value with 9AH.

ALGORITHM:

1. initialize counter register

2. move data in to A register

3. store the result in data field and display it in the data field.

4. initialize delay register

5. decrement delay register.

6. perform OR operation between high byte and low byte data.

7. if ZF = 1 go to step 8 or if ZF = 0 repeat 5 through 7.

8. move data from B register to A register

9. add 01H to data in A register

10. perform DAA instruction and move data to B register

11. compare data with 9AH and check the condition if ZF = 0 repeat steps 2

through step 11 or if ZF = 1 go to next step

12. jump to beginning of the program i.e step1.

SIR C R Reddy College of Engineering 54 Department of ECE

SIR C R Reddy College of Engineering 55 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8COOH O6 OO L3 MVI B,OOH ;initialize the counter register.

8CO2H 78 L2 MOV A,B ;move data into A register.

8CO3H 32 F1 8F STA 8FF1H ;

8CO6H C5 PUSH B ;display the result in data field.

8CO7H CD 4C O4 CALL O44CH ;

8COAH C1 POP B ;

8COBH 21 C2 C2 LXI H,C2C2H ;initialize the delay register.

8COEH 2B L1 DCX H ;decrement delay register.

8COFH 7D MOV A,L ;

8C1OH B4 ORA H ;perform OR operation.

8C11H C2 OE 8C JNZ L1 ;between high and lower byte

data.

8C14H 78 MOV A,B ;if ZF=0 go to L1. if ZF=1

,move data into A register

8C15H C6 O1 ADI O1H ;add O1H to data in A register.

8C17H 27 DAA ;get decimal data in

accumulator.

8C18H 47 MOV B,A ;move it to B register.

8C19H 3A 40 8C LDA 8C40H ;load accumulator with

desired count Value

8C1CH B8 CMP B ; compare the B register value

with A register value.

8C1DH C2 O2 8C JNZ L2 ;if ZF=0 go to L2.

8C2OH C3 OO 8C JMP L3 ;if ZF=1 go to L3.

SIR C R Reddy College of Engineering 56 Department of ECE

DECIMAL COUNTER

PROGRAM (B): Write a program to reset the decimal counter (00 to 99) at a predefined number

stored in the memory location 8C40H and start the count again.

PROBLEM ANALYSIS:

To design a counter is decimal counter from 00 to 99. Here we have to convert the

hexadecimal counter to decimal count. In this the process of counting is done using

a time delay process. In this counter we require numbers from 00 to 99. The

hexadecimal number is converted in to decimal number by using DAA instruction.

Since we require only number 00 to 99. We compare the value with 9AH.

ALGORITHM:

1. initialize counter register

2. move data in to A register

3. store the result in data field and display it in the data field.

4. initialize delay register

5. decrement delay register.

6. perform OR operation between high byte and low byte data.

7. if ZF = 1 go to step 8 or if ZF = 0 repeat 5 through 7.

8. move data from B register to A register

9. add 01H to data in A register

10. perform DAA instruction and move data to B register

11. compare data with 9AH and check the condition if ZF = 0 repeat steps 2

through step 11 or if ZF = 1 go to next step

12. jump to beginning of the program i.e step1.

SIR C R Reddy College of Engineering 57 Department of ECE

SIR C R Reddy College of Engineering 58 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE

8COOH O6 OO L3 MVI B,OOH ;initialize the counter register.

8CO2H 78 L2 MOV A,B ;move data into A register.

8CO3H 32 F1 8F STA 8FF1H ;

8CO6H C5 PUSH B ;display the result in data

field.

8CO7H CD 4C O4 CALL O44CH ;

8COAH C1 POP B ;

8COBH 21 C2 C2 LXI H,C2C2H ;initialize the delay register.

8COEH 2B L1 DCX H ;decrement delay register.

8COFH 7D MOV A,L ;

8C1OH B4 ORA H ;perform OR operation.

8C11H C2 OE 8C JNZ L1 ;between high and lower byte

data.

8C14H 78 MOV A,B ;if ZF=0 go to L1. if ZF=1

,move data into A register

8C15H C6 O1 ADI O1H ;add O1H to data in A register.

8C17H 27 DAA ;get decimal data in

accumulator.

8C18H 47 MOV B,A ;move it to B register.

8C19H 3A 40 8C LDA 8C40H ;load accumulator with

desired count Value

8C1CH B8 CMP B ; compare the B register value

with A register value.

8C1DH C2 O2 8C JNZ L2 ;if ZF=0 go to L2.

8C2OH C3 OO 8C JMP L3 ;if ZF=1 go to L3.

SIR C R Reddy College of Engineering 59 Department of ECE

CHECKING THE GIVEN CONDITION AND STORE THE RESPECTIVE

DATA IN MEMORY

PROGRAM:

Write a program to do the operation specified at a data memory location 8C40H.The

operations are specified as follows.00 – test parity of the data at 8C41H.and store

DD for odd parity and EE for even parity at memory location 8C42H.01- test the

zero condition of the data and store 00 if zero and FF if not, 02- test if the data is

positive or negative.

PROBLEM ANALYSIS:

In this program we have to perform a operation specified at a particular memory

location. If the memory location contains 00, we have perform a operation i.e

checking of parity condition. If it contains even number of ones some value is stored

in a memory location otherwise other value is stored in that memory location. If the

memory location contains, 01, we have to check the zero condition of the data

stored in a memory. If the memory location contains 02,we have to check the data

whether it is +ve or –ve .If it is +ve store some value, otherwise store some other

value in that memory location.

ALGORITHM:

1. store accumulator with some data.

2. perform AND operation with accumulator contents

3. if ZF = 1 go to next step or if ZF = 0 go to ahead (sub)step 5

4. call service routine to check parity condition

5. compare the accumulator data with 01H

6. If ZF = 1 go to next step or If ZF = 0 go to step 8

7. call service routine to check zero condition

8. compare the accumulator data with 02H

9. If ZF = 1 go to next step or If ZF = 0 go to step 11

10. call service routine to check sign condition.

11.stop

SIR C R Reddy College of Engineering 60 Department of ECE

SIR C R Reddy College of Engineering 61 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8C00H 3A 40 8C LDA 8C40H ; get the data in accumulator

8C03H A7 ANA A ; perform AND with acc

8C04H C2 0A 8C JNZ SUB ; if ZF =0 got o sub

8C07H CD 00 8D CALL 8D00H ; if ZF = 1 call

Service routine

8C0AH FE 01 SUB CPX 01H ; compare the acc data

With 02H

8C0CH C2 12 8C JNZ SUB1 ; if ZF= 0 go to sub1

8C0FH CD 20 8D CALL 8D20H ; if ZF =1 call service routine

8C12H FE 02 SUB1 CPI 02H ; compare the acc data

With 02H

8C14H C2 1A 8C JNZ SUB2 ; if ZF = 0 go to sub 2

8C17H CD 40 8D CALL 8D40H ; if ZF = 1 call a

Service routine

8C1AH 76 SUB2 HLT ; stop

SIR C R Reddy College of Engineering 62 Department of ECE

SIR C R Reddy College of Engineering 63 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8D00H 3A 41 8C LDA 8C41H ; get the data in accumulator

8D03H B7 ORA A ; perform OR with acc

8D04H 3E DD MVI A, DDH ; move data DDH in to acc

8D06H E2 0B 8D JPO AHEAD ; if P= 0 go to head

8D09H 3E EE MVI A, EEH ; if P=1 move FFH to acc

8D0BH 3E 42 8C AHEAD STA 8C42H ; store the result in memory

Location 8C42H

8D0EH 76 HLT ; stop

SIR C R Reddy College of Engineering 64 Department of ECE

ALGORITHM:

1. load data in to accumulator

2. perform OR operation with accumulator contents.

3. move data DDH in the accumulator

4. If P= 0 go to step- 6 or If P= 1 go to next step

5. move data EEH in to accumulator

6. store the result in memory location specified

7. stop

ALGORITHM:

1. load data in to accumulator

2. perform AND operation with accumulator contents.

3. move data FFH in the accumulator

4. If ZF= 0 go to step- 6 or If ZF= 1 go to next step

5. complement accumulator

6. store the result in memory location specified

7. stop

ALGORITHM:

1. load data in to accumulator

2. perform AND operation with accumulator contents.

3. move data 01H in the accumulator

4. If S= 0 go to step- 6 or If S= 1 go to next step

5. move data 02H in to accumulator

6. store the result in memory location specified

7. stop

SIR C R Reddy College of Engineering 65 Department of ECE

SIR C R Reddy College of Engineering 66 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8D20H 3A 41 8C LDA 8C41H ; get the data in accumulator

8D23H A7 ANA A ; perform AND operation

with accumulator

8D24H 3E FF MVI A, FFH ; move data FFH in to acc

8D26H C2 2A 8D JNZ AHEAD1 ; if ZF=1go to ahead 1

8D29H 2F CMA ; if ZF=0 complement acc

8D2AH 3E 42 8C AHEAD1STA 8C42H ; store the result in memory

8D2DH 76 HLT ; stop

SIR C R Reddy College of Engineering 67 Department of ECE

SIR C R Reddy College of Engineering 68 Department of ECE

ASSEMBLY LANGUAGE PROGRAM: MEMORY MACHINE LABEL MNEMONIC COMMENT LOCATION CODE 8D40H 3A 41 8C LDA 8C41H ; get the data in accumulator

8D43H A7 ANA A ; perform AND operation

with accumulator

8D44H 3E FF MVI A,01H ; move data 01H in to acc

8D46H F2 4B 8D JP AHEAD2 ; if P=1go to ahead 2

8D49H 3E 02 MVI A, 02H ; if P=0 move data 02H

into acc

8D4BH 3E 42 8C AHEAD2STA 8C42H ; store the result in memory

8D4EH 76 HLT ; stop