Find the minimum value in a given array | 8086 Microprocessor

In this tutorial, we will learn how to write an assembly language program in 8086 Microprocessor to find the minimum value in a given range? By Ayush Sharma Last updated : May 22, 2023

Problem Statement

Write a program to find the minimum value in a given array in assembly 8086 Microprocessor.

Assumptions: Starting address of input array is 0500 and stores the result at address 0600.

Algorithm

  1. Assign value 500 in SI and 600 in DI
  2. Move the contents of [SI] in CL and increment SI by 1
  3. Assign the value 00 H to CH
  4. Move the content of [SI] in AL
  5. Decrease the value of CX by 1
  6. Increase the value of SI by 1
  7. Move the contents of [SI] in BL
  8. Compare the value of BL with AL
  9. Jump to step 11 if carry flag is set
  10. Move the contents of BL in AL
  11. Jump to step 6 until the value of CX becomes 0, and decrease CX by 1
  12. Move the contents of AL in [DI]
  13. Halt the program

Program

ADDRESSMNEMONICSCOMMENTS
0400MOV SI, 500SI ← 500
0403MOV DI, 600DI ← 600
0406MOV CL, [SI] CL ← [SI]
0408MOV CH, 00 CH ← 00
040AINC SI SI ← SI+1
040BMOV AL, [SI] AL ← [SI]
040DDEC CX CX ← CX-1
040EINC SI SI ← SI+1
040FMOV BL, [SI] BL ← [SI]
0411CMP AL, BL AL-BL
0413JC 0417 Jump if carry is 1
0415MOV AL, BL AL ← BL
0417LOOP 040E Jump if CX not equal to 0
0419MOV [DI], AL [DI] ← AL
041BHLT 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



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.