0% found this document useful (0 votes)
42 views35 pages

CO Lab Manual

Uploaded by

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

CO Lab Manual

Uploaded by

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

Effective from the year 2023

INTRODUCTION TO COMPUTER ARCHITECTURE AND


MICROPROCESSOR LAB MANUAL

DEPARTMENT : COMPUTER SCIENCE

CLASS : BSC

YEAR : I BSC

SEMESTER : II

SUBCODE : 125C21
INTRODUCTION TO COMPUTER ARCHITECTURE AND
MICROPROCESSOR LAB MANUAL

DEPARTMENT : COMPUTER SCIENCE

CLASS : BSC

YEAR : I BSC

SEMESTER : II

SUBCODE : 125C21

Prepared by Approved by
I : Addition and Subtraction
1. 8 - bit addition
2. 16 - bit addition
3. 8 - bit subtraction
4. BCD subtraction

II : Multiplication and Division


l . 8 - bit multiplication
2. BCD multiplication
3. 8 - bit division
III: Sorting and Searching
1. Searching for an element in an array.
2. Sorting in ascending order.
3. Finding largest and smallest elements from an array
4. Reversing array elements
5. Block move
6. Sorting in descending order
IV: Code Conversion
l. BCD to Hex and Hex to BCD
2. Binary to ASCII and ASCII to binary
3. ASCII to BCD and BCD to ASCII
V: Applications
1. Square of a single byte Hex number
2. Square of a two digit BCD number
3. Square root of a single byte Hex number
4. Square root of a two digit BCD number
1. 8 – BIT ADDITION

Aim:

To perform addition of two 8 bits numbers using 8085 simulator.

Algorithm:

1. Load the accumulator with the first data.


2. Move data of accumulator to register B.
3. Load the second data into the accumulator.
4. Add the content of register B with the content of accumulator.
5. Now load the result value in a memory location.

Program Coding:

LDA 2050
MOV B,A
LDA 2051
ADD B
STA 2052
HLT

Input:

2050 04

2051 02

Output

2052 06

RESULT:
Thus the above program has been successfully executed and completed.
2. 16 Bit Addition

Aim:

To add two 16 bits numbers in 8085 Simulator using 16 bits operation.

Algorithm:

1. Load both the lower bit and higher bit of first number at once.
2. Copy the content HL pair to DE pair register.
3. Now the load the lower and higher bit of second number in HL pair register.
4. ADD both the register pair content using DAD operation.
5. Result will store in HL register
6. Stop

Program coding:

LXI D,1122H

LXI H,1122H

DAD D

HLT

Input:

DE 1122

HL 1122

Output:

HL 2244

RESULT:
Thus the above program has been successfully executed and completed.
3. 8 Bit Subtraction

Aim:

To perform subtraction of two 8 bits numbers using 8085 simulator.

Algorithm:

1. Load the accumulator with the first data.


2. Move data of accumulator to register B.
3. Load the second data into the accumulator.
4. Subtract the content of register B with the content of accumulator.
5. Now load the result value in a memory location.

Program Coding:

LDA 2050
MOV B,A
LDA 2051
SUB B
STA 2052
HLT

Input:

2050 02

2051 04

Output

2052 02

RESULT:
Thus the above program has been successfully executed and completed.

4 . BCD Subtraction
Aim:

To perform BCD subtraction using 8085 simulator.

Algorithm –

1. Load the data from address 2051 in A


2. Move the data from A to C
3. Move the data 99 in A
4. Subtract the contents of registers A and C
5. Increment the content of A by 1
6. Move the data from A to B
7. Load the data from address 2050 in A
8. Add the contents of A and C and adjust it in BCD format by using DAA instruction
9. Store the result at memory address 2080
10. Stop

Program coding:

LDA 2051H
MOV C,A
MVI A,99H
SUB C
INR A
MOV B,A
LDA 2050H
ADD B
DAA
STA 2080H
HLT

OBSERVATION:
INPUT:
2050: 70
2051: 30
OUTPUT:
2080: 40
RESULT:
Thus the above program has been successfully executed and completed.

II : Multiplication and Division


8 BIT MULTIPLICATION
Aim:

To perform multiplication of two 8 bits numbers using 8085 simulator.

Algorithm:

1. Load the data from the address 2050 to the HL pair register.
2. Move the contents from the register M to B register.
3. Increment the HL pair register
4. Move the contents from the register M to C register.
5. Clear the A register
6. Add the memory contents with the register B
7. Decrement the register C
8. Jump to loop when Z flag is not 1
9. Increment the HL pair register
10. Store Acc contents into the memory
11. Terminate the program.

Program coding:

LXI H,2050H
MOV B,M
INX H
MOV C,M
MVI A,00H
TOP:ADD B
DCR C
JNZ TOP
INX H
MOV M,A
HLT

Observation:

Input:
2050: 03
2051: 04
Output:
2052: 0C

RESULT:
Thus the above program has been successfully executed and completed.

BCD MULTIPLICATION

Aim:
To perform BCD multiplication of two 8 bits numbers using 8085 simulator.

Algorithm:
1. Load the BCD multiplier
2. Initialize counter
3. Set Result register to 0000
4. Load the multiplicand
5. Extend the registers to 16-bits
6. Result = Result + Multiplicand
7. Get the lower byte of the result
8. Adjust the lower byte of result to BCD.
9. Store the lower byte of result
10. Increment counter, adjust it to BCD and store it
11. Compare if count = multiplier
12. Jump to loop when Z flag is not 1
13. Terminate the program

Program coding:
MVI C,03H
MVI B,00h
LXI H,0000H
MVI E,03h
MVI D,00H
BACK:DAD D
MOV A,L
ADI 00H
DAA
MOV L,A
MOV A,H
ACI 00H
DAA
MOV H,A
MOV A,B
ADI 01H
DAA
MOV B,A
CMP C
JNZ BACK
HLT

Input:
BC: 03 03
DE: 00 03
Output:
HL: 00 09
RESULT:
Thus the above program has been successfully executed and completed.
8 BIT DIVISION

Aim:

To perform division of two 8 bits numbers using 8085 simulator.

Algorithm:

1. Load the data from the address 2051 into the Acc
2. Move the contents from register A to register B
3. Load the second data into accumulator.
4. Clear the register C
5. Compare the two numbers to check carry.
6. Subtract two numbers.
7. Increment the value of carry.
8. Check whether the repeated subtraction is over.
9. Then store the results (quotient and remainder) in given memory location.
10. Terminate the program.

Program coding:

LDA 2051H
MOV B,A
LDA 2052H
MVI C,00H
LOOP2:CMP B
JC LOOP1
SUB B
INR C
JMP LOOP2
LOOP1:STA 2053H
MOV A,C
STA 2054H
HLT

Observation:
Input:
2051: 03
2052: 07

Output:
2053: 01
2054: 02

RESULT:
Thus the above program has been successfully executed and completed.
III: Sorting and Searching

Searching for an element in an array.


Aim:
To to search a given number in an array of n numbers. If number is found, then store
F0 in memory location 3051 otherwise store 0F in 3051.
Algorithm:
1. Make the memory pointer points to memory location 2050 by help of LXI H 2050 instruction
2. Store value of array size in register C
3. Store number to be search in register B
4. Increment memory pointer by 1 so that it points to next array index
5. Store element of array in accumulator A and compare it with value of B
6. If both are same i.e. if ZF = 1 then store F0 in A and store the result in memory location 3051
and go to step 9
7. Otherwise store 0F in A and store it in memory location 3051
8. Decrement C by 01 and check if C is not equal to zero i.e. ZF = 0, if true go to step 3
otherwise go to step 9
9. End of program

Program coding:
2000 LXI H 2050
2003 MOV C, M
2004 LDA 3050
2007 MOV B, A
2008 INX H
2009 MOV A, M
200A CMP B
200B JNZ 2014
200E MVI A F0
2010 STA 3051
2013 HLT
2014 MVI A 0F
2016 STA 3051
2019 DCR C
201A JNZ 2008
201D HLT

Input:
2050 04
2051 49
2052 F2
2053 14
2054 39

Output:
3050 F2
3051 F0
3050 17
3051 0F

RESULT:
Thus the above program has been successfully executed and completed.

SORTING IN ASCENDING ORDER


Aim:

To perform the sorting in ascending order using 8085 simulator.

Algorithm:

1) Initialize HL pair as memory pointer.


2) Get the count at 2200 in to H register.
3) Copy it in the register.
4) Get the first value in Accumulator.
5) Compare it with the value at next location.
6) If they are out of order, exchange the contents of accumulator and memory.
7) Decrement H register’s content by 1.
8) Repeat steps 5 and 7 till the value in the register become zero.
9) Decrement B register’s content by 1.
10) Repeat steps 3 to 9 till the value in the register becomes zero.
11) Terminate the program.

Program coding:
MVI B,09H
START:LXI H,2200H
MVI C,09H
BACK: MOV A, M
INX H
CMP M
JC SKIP
JZ SKIP
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
SKIP:DCR C
JNZ BACK
DCR B
JNZ START
HLT

INPUT:
2200 : FF
2201: 08
2202: DD
2203: E7
2204: 95
OUTPUT:
2205: 08
2206: 95
2207: DD
2208: E6
2209: FF
RESULT:
Thus the above program has been successfully executed and completed.

Finding largest and smallest elements from an array

Aim:
To find the largest & smallest elements from an array using 8085 simulator.
Algorithm:
1. Load the address of the first element of the array in HL pair.
2. Move the count to B - reg.
3. Increment the pointer.
4. Get the first data in A - reg.
5. Decrement the count.
6. Increment the pointer.
7. Compare the content of memory addressed by HL pair with that of A - reg.
8. If carry = 1, go to step 10 or if Carry = 0 go to step 9.
9. Move the content of memory addressed by HL to A - reg.
10. Decrement the count.
11. Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
12. Store the smallest data in memory.
13. Terminate the program.
Program coding:
a. SMALLEST ELEMENTS FROM AN ARRAY
LXI H,2000H
MOV C,M
INX H
MOV B,M
DCR C
LOOP:INX H
MOV A,M
CMP B
JNC SKIP
MOV B,A
SKIP:DCR C
JNZ LOOP
LXI H,2072H
MOV M,B
HLT

Observation
Input:
2000 : 05
2001: 2B
2002: 91
2003: 06
2004: 35
2005: 02
OUTPUT:
2072: 02
b. LARGEST ELEMENT IN AN ARRAY
Aim:
To find the largest element in an array using 8085 simulator.
Algorithm:
1. Load HL pair with address of first operand’s memory address location.
2. Move the first operand from memory to Acc
3. Increment HL pair to point to next memory location.
4. Move the second operand from memory to the register
5. Compare it with the two registers
6. If jump not carry, move the data from register to the Acc.
7. Increment HL pair register
8. Move the result from Acc to memory
9. Terminate the program.

PROGRAM:
LXI H,2000H
MOV B,M
INX H
MOV A,M
DCR B
NEXT:INX H
CMP M
JNC LOOP
MOV A,M
LOOP:DCR B
JNZ NEXT
STA 2072H
HLT
Input:
2000 : 03
2001: 91
2002: 25
2003: 4B
2004: 61
OUTPUT:
2072: 91
RESULT:
Thus the above program has been successfully executed and completed.

REVERSING ARRAY ELEMENTS


Aim:
To reverse the array elements using 8085 simulator.

Algorithm:
1. Take the block size into C

2. Point to the destination address

3. Load M into A

4. Store A into destination pointed by DE

5. Point source to previous address

6. Point destination to next address

7. Decrease C by 1

8. if Z is not set jump to NEXT

9. Terminate the program

Program coding:
MVI C,5
LXI H,2004H
LXI D,2070H
NEXT:MOV A,M
STAX D
DCX H
INX D
DCR C
JNZ NEXT
HLT
Observation
Input:
2000 : 10
2001: 20
2002: 30
2003: 40
2004: 50
Output:
2070 : 50
2071: 40
2072: 30
2073: 20
2074: 10
RESULT:
Thus the above program has been successfully executed and completed.
Block move

Aim:
To move the block of contents from one memory location to another memory
location.
Algorithm:
1. Load register pair H-L with the address 2000H
2. Load register pair D-E with the address 2070H
3. Move the content at memory location into accumulator
4. Store the content of accumulator into memory pointed by D-E
5. Increment value of register pair H-L and D-E by 1
6. Decrements value of register C by 1
7. If zero flag not equal to 1, go to step 3
8. Terminate the program

Program coding:
MVI C,5
LXI H,2000H
LXI D,2070H
NEXT:MOV A,M
STAX D
INX H
INX D
DCR C
JNZ NEXT
HLT

Input:
2000 : 10
2001: 20
2002: 30
2003: 40
2004: 50
Output:
2070 : 10
2071: 20
2072: 30
2073: 40
2074: 50

RESULT:
Thus the above program has been successfully executed and completed.

SORTING IN DESCENDING ORDER

Aim:
To perform the sorting in descending order using 8085 simulator.
Algorithm:
1) Initialize HL pair as memory pointer.
2) Get the count at 2200 in to C register.
3) Copy it in the register.
4) Get the first vale in Accumulator.
5) Compare it with the value at next location.
6) Jump if not carry go the label skip.
7) If they are out of order, exchange the contents of accumulator and memory.
8) Decrement H register’s content by 1.
9) Repeat steps 5 and 7 till the value in the register become zero.
10) Decrement B register’s content by 1.
11) Repeat steps 3 to 9 till the value in the register becomes zero.
12) Terminate the program.

Program:
MVI B,09H
START:LXI H,2200H
MVI C,09H
BACK: MOV A, M
INX H
CMP M
JNC SKIP
JZ SKIP
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
SKIP:DCR C
JNZ BACK
DCR B
JNZ START
HLT
OBSERVATION:
INPUT:
2200 : FF
2201: 08
2202: DD
2203: E7
2204: 95
OUTPUT:
2200 : FF
2201: E7
2202: DD
2203: 95
2204: 08
RESULT:
Thus the above program has been successfully executed and completed.
IV: Code Conversion
l. BCD to Hex and Hex to BCD

Aim:
To convert Binary coded decimal into Hexadecimal using 8085 simulator.
Algorithm:
1. Load HL pair in 2000H & 2001H
2. Move contents into A
3. Add A(A*2)
4. Store in Register B
5. Add A(A*4)
6. Add A(A*8)
7. Add B(A*10)
8. Increment the memory location
9. Store the result in 2002H
10. Terminate the Program.
Program Coding:
LXI H,2000H
MOV A,M
ADD A
MOV B,A
ADD A
ADD A
ADD B
INX H
ADD M
INX H
MOV M,A
HLT
Input:
2000 02
2001 09
Output:
2002 00
RESULT:
Thus the above program has been successfully executed and completed.

Hexa to BCD conversion


Aim:
To convert the hexa decimal into Binary coded decimal using 8085
simulator.
Algorithm:
1. Load HL pair in 2000H
2. Load 00 in D Register
3. Clear the accumulator
4. Move contents into C
5. Add immediate data 1 in A
6. Decimal Adjust
7. Jump on No Carry to Loop2
8. Increment D Register
9. Decrement C Register
10. Jump on Non-Zero to Loop1
11. Store Result in 2002H
12. Move upper byte into A
13. Store the Result in 2001H
14. Terminate the program.
Program coding:
LXI H,2000H
MVI D,00H
XRA A
MOV C,M
LOOP1:ADI 01H
DAA
JNC LOOP2
INR D
LOOP2: DCR C
JNZ LOOP1
STA 2002H
MOV A,D
STA 2001H
HLT
Input:
2000 FF
Output:
2001 02
2002 55
RESULT:
Thus the above program has been successfully executed and completed.

Binary to ASCII and ASCII to binary


BINARY TO ASCII CONVERSION

Aim:
To convert binary to ASCII using 8085 simulator.

Algorithm:
1. Load the address 2200 to the accumulator.
2. Compare the content of accumulator with 0A
3. Start the loop
4. ADI 07 will add 07 to the content of the accumulator.
5. It will add 37 to the content of the accumulator.
6. Store the result in the address 2260.
7. Terminate the program.

Program coding:

LDA 2200H ; BIN TO ASCII


CPI 0AH
JC NEXT
ADI 07H
NEXT:ADI 30H
STA 2260H
HLT

INPUT:
2200 : 0B

OUTPUT:
2260: 42

2002 55
RESULT:
Thus the above program has been successfully executed and completed.

ASCII TO BINARY CONVERSION

Aim:
To convert ASCII to binary using 8085 simulator.

Algorithm:
1. Load the address 2200 to the accumulator.
2. SUI 30 will subtract 30 to the content of the accumulator.
3. Compare the content of accumulator with 0A
4. Start the loop
5. SUI 07 will subtract 07 to the content of the accumulator.
6. It will subtract 37 to the content of the accumulator.
7. Store the result in the address 2270.
8. Terminate the program.

Program coding:

LDA 2200H ; ASCII TO BINARY CONVERSION


SUI 30H
CPI 0AH
JC NEXT
SUI 07H
NEXT:STA 2270H
HLT

INPUT:
2200 : 44

OUTPUT:
2270: 0D

RESULT:
Thus the above program has been successfully executed and completed.

ASCII to BCD and BCD to ASCII

ASCII TO BCD CONVERSION


Aim:
To convert ASCII to Binary coded decimal using 8085 simulator.
Algorithm:
1. Load the address 8010 to the accumulator.
2. SUI 30 will subtract 30 to the content of the accumulator.
3. Store the result in the address 8080.
4. Terminate the program.

Program coding:
LDA 8010H
SUI 30H
STA 8080H
HLT

INPUT:
8010: 35

OUTPUT:
8080: 05

RESULT:
Thus the above program has been successfully executed and completed.

BCD TO ASCII CONVERSION


Aim:
To convert ASCII to Binary coded decimal using 8085 simulator.
Algorithm:
1. Load the address 8010 to the accumulator.
2. ADI 30 will add 30 to the content of the accumulator.
3. Store the result in the address 8080.
4. Terminate the program.

Program coding:
LDA 8010H
ADI 30H
STA 8080H
HLT

INPUT:
8010: 08

OUTPUT:
8080: 38

RESULT:
Thus the above program has been successfully executed and completed.

V: Applications
1. Square of a single byte Hex number
Aim:
To find the square of a single byte to hex number using 8085 simulator.
Algorithm:
1. Load the HL pair register to a memory location
2. Initialize the Acc
3. Move the contents of the memory location which is indirectly specified by M
in register C
4. Add the contents of the memory location
5. Decrement value of register C by 1.
6. Jump to the loop if ZF=0
7. Stores the values in 2051
8. Terminate the program

Program coding:

LXI H,2000H
MVI A,00H
MOV B,M
MOV C,M
LOOP:ADD B
DCR C
JNZ LOOP
STA 2051H
HLT

Input:
2000 : 05
Output:
2051 : 19

RESULT:
Thus the above program has been successfully executed and completed.

Square of a two digit BCD number


Aim:
To find the square of a two digit BCD number using 8085 simulator.
Algorithm:

1. Load first operand address


2. Store first operand to B

3. Increase HLpair

4. Store second operand to register C

5. Clear register E & Clear H register & Clear A register

6. Compare C with A

7. When Z = 0,jump to DONE

8. Add B with A

9. Decimal Adjust
10. Store A to D

11. Jump tp NINC

12. Store H to A & Restore H from A

13. Load E to A & Increase A by1

14. Decimal adjust

15. Restore E from A & Compare C with A

16. Load D to A & Jump to LOOP

17. Load A to L & Store HL pair at location 8050 and 8051

18. Terminate the program


Program coding:
LXI H,8000H
MOV B, M

INX H

MOV C, M

MVI E, 00H

MOV H, E

MOV A, E

CMP C

JZ DONE

LOOP ADD B

DAA

MOV D, A

JNC NINC

MOV A, H

ADI 01H

DAA

MOV H, A

NINC MOV A, E
ADI 01H

DAA

MOV E, A

CMP C

MOV A,D

JNZ LOOP

DONE MOV L, A

SHLD 8050H

HLT
Input:
8000 12
8001 20
Output:
8050 40
8051 02
Result:
Thus the above program has been successfully executed and completed.

SQUARE ROOT OF A SINGLE BYTE HEX NUMBER

Aim:
To find the square root of a single byte to hex number using 8085
simulator.

Algorithm:
1. Load the value, stored at memory location 2200 in accumulator A
2. Assign 01 to register B and C
3. Subtract value stored at accumulator A from register B
4. Check if accumulator holds 0, if true then jump to step 8
5. Increment value of register D by 2
6. Increment value of register C by 1
7. Jump to step 3
8. Move value stored at register C in A
9. Store the value of A in memory location 2272
10. Terminate the program
Program coding:

LDA 2200H
MVI B,01H
MVI C,01H
AGAIN:SUB B
JZ OVER
INR C
INR B
INR B
JMP AGAIN
OVER:MOV A,C
STA 2272H
HLT

Input:
2200 09

Output:
2272 03

RESULT:
Thus the above program has been successfully executed and completed.

SQUARE ROOT OF A TWO DIGIT BCD NUMBER

Aim:
To find the square root of a two digit binary coded decimal number using 8085
simulator.

Algorithm:
1. Assign 01 to register D and E
2. Load the value, stored at memory location 2050 in accumulator A
3. Subtract value stored at accumulator A from register D
4. Check if accumulator holds 0, if true then jump to step 8
5. Increment value of register D by 2
6. Increment value of register E by 1
7. Jump to step 3
8. Move value stored at register E in A
9. Store the value of A in memory location 3050

Program coding:
MVI D, 01

MVI E, 01

LDA 2050

SUB D

JZ 2011

INR D

INR D

INR E

JMP 2007

MOV A, E

STA 3050

HLT

INPUT:
2050 09
Output
3050 03
RESULT:
Thus the above program has been successfully executed and completed.

ADDITIONAL EXERCISES:

1. PROGRAM TO ADD CONTENTS OF TWO MEMORY LOCATIONS

Aim:

To add contents of two memory locations.

Algorithm:

1. HL Points 2500H
2. Get first operand
3. HL Points 2501H
4. Add second operand
5. HL Points 2502H
6. Store the lower byte of result at 2502H
7. Initialize higher byte result with 00H
8. Add carry in the high byte result
9. HL Points 2503H
10. Store the higher byte of result at 2503H
11. Terminate program execution

Program

1. LXI H, 2500H
2. MOV A, M
INX H
ADD M
INX H
MOV M, A
MVIA, 00
ADC A
INX H
MOV M, A
HLT

OUTPUT:
(2500H) = 7FH
(2501H) = 89H
Result = 7FH + 89H = lO8H
(2502H) = 08H
(2503H) = 01H

2. PROGRAM TO FIND 1’S COMPLEMENT OF A NUMBER

Aim:

To find 1’s complement of a number.

Algorithm:

1. Get the number IN accumulator

2. take its complement


3. Store result in 2502H
4. Stop

PROGRAM:

LDA 2501H

1. CMA
2. STA 2502H
3. HLT

4.

OUTPUT:
(2501H) = 96 H = 1001 0110
(9) (6)
One's complement = 0110 1001 = 69 H
Result = (2502H) = 69H

3. PROGRAM TO FIND 2’S COMPLEMENT OF A NUMBER

AIM:

To find 1’s complement of a number.

ALGORITHM:

1. Get data in accumulator


2. Take its 1's complement
3. Add one in the number
4. Store the result in 2502 H
5. Stop

PROGRAM:

1. LDA 2501 H
2. CMA
3. ADI, 01 H
4. STA 2502 H
5. HLT
OUTPUT:
To find the two's complement of 96.
96 = 1001 0110
1's complement = 0110 1001 = 69
+ 0000 0001
2's complement = 0110 1010 = 6A

4. PROGRAM TO Count number of 1's in a number

AIM:

To count number of 1’s in a number.

Algorithm:

1. Get data in registers.


2. Count the number of 1’s
3. Increment the variable
4. Print the result
5. Stop the program.

Program

Count number of 1's of the content of the register D and store the count in the register B.

1. MVI B, 00H
2. MVI C, 08H
3. MOV A, D
4. BACK: RAR
5. JNC SKIP
6. INR B
7. SKIP: DCR C
8. JNZ BACK
9. HLT

OUTPUT:
2501 H = 04
2502 H = 34 H
2503 H = A9H
2504 H = 78H
2505 H = 56H
Result = 2503 H = A9H

5. PROGRAM TO Calculate the sum of series of odd numbers

Aim:

To calculate the sum of series of odd numbers.

Algorithm:

1. Initialize counter
2. Initialize pointer
3. Sum low = 0
4. Sum high = 0
5. Get the number"
6. Mask Bit 1 to Bit-7
7. Don't add if number is even
8. Get the lower byte of sum
9. Sum = sum + data
10. Store result in E register
11. Add carry to MSB of SUM
12. Increment pointer

Program

1. LDA 2500H
2. MOV C, A
3. LXI H, 2501H
4. MVI E, 00
5. MOV D, E
6. BACK: MOV A, M
7. ANI 01H
8. JZ SKIP
9. MOV A, E
ADD M
MOV E, A
JNC SKIP
INR D
SKIP: INX H

OUTPUT:
2500 H = 4H

2501 H = 9AH

2502 H = 52H
2503 H = 89H
2504 H = 3FH
Result = 2505 H = 89H + 3FH= C8H

You might also like