Skip to content
Related Articles

Related Articles

Improve Article
8086 program to find the min value in a given array
  • Last Updated : 22 May, 2018

Problem – Write a program to find the min value in a given array in assembly 8086 microprocessor

Example –

Assumptions – Starting address of input array is 0500 and and store 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 –

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

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :