[go: up one dir, main page]

0% found this document useful (0 votes)
18 views6 pages

COA LAB 2 3 4 Experiments Manual

The document contains assembly language programs for various tasks including finding the smallest number in an array, adding two arrays, and separating even and odd numbers from a list. Each program includes a detailed explanation of the steps involved and the corresponding assembly instructions. The programs are designed for 8086 and 8085 microprocessors and demonstrate basic operations like moving data, looping, and conditional jumps.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

COA LAB 2 3 4 Experiments Manual

The document contains assembly language programs for various tasks including finding the smallest number in an array, adding two arrays, and separating even and odd numbers from a list. Each program includes a detailed explanation of the steps involved and the corresponding assembly instructions. The programs are designed for 8086 and 8085 microprocessors and demonstrate basic operations like moving data, looping, and conditional jumps.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT: 2 ( b ) A s s e m b l y language program to find smallest

number in an array

AIM: Assembly language program to find smallest number in an


array

MEMORY ADDRESS MNEMONICS COMMENTS

0400 MOV SI, 500 SI <- 500

0403 MOV DI, 600 DI <- 600

0406 MOV CL, [SI] CL <- [SI]

0408 MOV CH, 00 CH <- 00

040A INC SI SI <- SI+1

040B MOV AL, [SI] AL <- [SI]

040D DEC CX CX <- CX-1

040E INC SI SI <- SI+1

040F MOV BL, [SI] BL <- [SI]

0411 CMP AL, BL AL-BL

0413 JC 0417 Jump if carry is 1

0415 MOV AL, BL AL <- BL

0417 LOOP 040E Jump if CX not equal to 0

0419 MOV [DI], AL [DI] <- AL

041B HLT End of the program


Explanation –

1. MOV SI, 500 assigns 500 to SI

2. MOV DI, 600 assigns 600 to DI

3. MOV CL, [SI] moves the content of [SI] to CL register

4. MOV CH, 00 assign 00 to CH register

5. INC SI increase the value SI by 1

6. MOV AL, [SI] moves the content of [SI] to AL register

7. DEC CX decrease the content of CX register by 1

8. INC SI increase the value SI by 1

9. MOV BL, [SI] moves the content of [SI] to BL register

10. CMP AL, BL subtract the value of BL register from AL and it modify flag registers

11. JC 0417 jump to 0417 address if carry flag is set

12. MOV AL, BL moves the content of BL register to AL register

13. LOOP 040E runs loop till CX not equal to Zero and decrease the value of CX by 1

14. MOV [DI], AL moves the content of AL to [DI]

15. HLT stops the execution of program

Example:
LAB NO 3(b) Assembly language program for adding to two arrays

Problem Statement

Write a program in 8086 microprocessor to find out the sum of two arrays of 8-bit n numbers,
where size “n” is stored at offset 500 and the numbers of first array are stored from offset 501
and the numbers of second array are stored from offset 601 and store the result numbers into
first array i.e offset 501.

Algorithm

1. Store 500 to SI and 601 to DI and Load data from offset 500 to register CL and set register CH
to 00 (for count).
2. Increase the value of SI by 1.
3. Load first number (value) from next offset (i.e 501) to register AL.
4. Add the value in register AL by value at offset DI.
5. Store the result (value of register AL ) to memory offset SI.
6. Increase the value of SI by 1.
7. Increase the value of DI by 1.
8. Loop above 5 till register CX gets 0.

Program
MEMORY ADDRESS MNEMONICS COMMENT
400 MOV SI, 500 SI←500
403 MOV CL, [SI] CL←[SI]
405 MOV CH, 00 CH←00
407 INC SI SI←SI+1
408 MOV DI, 601 DI←601
40B MOV AL, [SI] AL←[SI]
40D ADD AL, [DI] AL=AL+[DI]
40F MOV [SI], AL AL->[SI]
411 INC SI SI←SI+1
412 INC DI DI←DI+1
413 LOOP 40B JUMP TO 40B IF CX!=0 and CX=CX-1
415 HLT End

Explanation

1. MOV SI, 500: set the value of SI to 500


2. MOV CL, [SI]: load data from offset SI to register CL
3. MOV CH, 00: set value of register CH to 00
4. INC SI: increase value of SI by 1.
5. MOV DI, 600: set the value of DI to 600.
6. MOV AL, [SI]: load value from offset SI to register AL
7. ADD AL, [DI]: Add value of register AL by content at offset DI.
8. MOV [SI], AL: store value of register AL at offset SI.
9. INC SI: increase value of SI by 1.
10. INC DI: increase value of DI by 1.
11. LOOP 408: jump to address 408 if CX not 0 and CX=CX-1.
12. HLT: stop
4(b) Assembly language program to separate even and odd numbers from an array

Problem: Write an assembly language program in 8085 microprocessor to separate odd and
even numbers from the given list of 50 numbers. Store odd nos in another list starting from
memory location 2100H. Store even nos in another list starting from memory location 2200H.
Starting address of the list is 2000H.

Explanation:
A number is said to be odd if its least significant bit is 1 otherwise it is even. Therefore to
identify whether the number is even or odd, we perform AND operation with 01 by the help of
ANI instruction. If the number is odd then we will get 01 otherwise 00 in the accumulator. ANI
instruction also affects the flags of 8085. Therefore if accumulator contains 00 then zero flag
gets set otherwise it gets reset.

Example:

Algorithm:

1. Load the memory location 2000 in HL register pair.


2. Load the memory location 2100 in DE register pair for storing odd numbers.
3. Store the number of elements in register C.
4. Move the next number in the list to accumulator.
5. Perform AND operation with 01H to check whether the number is even or odd.
6. If even, jump to step 9.
7. Get the number in accumulator and store in the memory location pointed by DE.
8. Increment DE.
9. Increment HL. Decrement C.
10. If C is not zero, jump to step
Program:

Memory Location Mneumonics Comments


2000H LXI H, 2000H Initialize memory pointer 1
2003H LXI D, 2100H Initialize memory pointer 2
2006H MVI C, 32H Initialize counter
2008H MOV A, M Get the number
2009H ANI 0lH Check for odd number
200BH JZ 2011H If EVEN, don’t store
200EH MOV A, M Get the number
200FH STAX D Store the number in result list
2010H INX D Increment pointer 2
2011H INX H Increment pointer l
2012H DCR C Decrement counter
2013H JNZ 2008H If not zero, repeat
2016H LXI H, 2000H Initialize memory pointer l
2019H LXI D, 2200H Initialize memory pointer2
201CH MVI C, 32H Initialize counter
201EH MOV A, M Get the number
201FH ANI 0lH Check for even number
2021H JNZ 2027H If ODD, don’t store
2024H MOV A, M Get the number
2025H STAX D Store the number in result list
2026H INX D Increment pointer 2
2027H INX H Increment pointer l
Decrement counter

2028H DCR C

JNZ 201EH If not zero, repeat


2029H
202CH HLT Stop

You might also like