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 store the result at address 0600
Algorithm –
- Assign value 500 in SI and 600 in DI
- Move the contents of [SI] in CL and increment SI by 1
- Assign the value 00 H to CH
- Move the content of [SI] in AL
- Decrease the value of CX by 1
- Increase the value of SI by 1
- Move the contents of [SI] in BL
- Compare the value of BL with AL
- Jump to step 11 if carry flag is set
- Move the contents of BL in AL
- Jump to step 6 until the value of CX becomes 0, and decrease CX by 1
- Move the contents of AL in [DI]
- Halt the program
Program –
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 –
- MOV SI, 500 assigns 500 to SI
- MOV DI, 600 assigns 600 to DI
- MOV CL, [SI] moves the content of [SI] to CL register
- MOV CH, 00 assign 00 to CH register
- INC SI increase the value SI by 1
- MOV AL, [SI] moves the content of [SI] to AL register
- DEC CX decrease the content of CX register by 1
- INC SI increase the value SI by 1
- MOV BL, [SI] moves the content of [SI] to BL register
- CMP AL, BL subtract the value of BL register from AL and it modify flag registers
- JC 0417 jump to 0417 address if carry flag is set
- MOV AL, BL moves the content of BL register to AL register
- LOOP 040E runs loop till CX not equal to Zero and decrease the value of CX by 1
- MOV [DI], AL moves the content of AL to [DI]
- HLT stops the execution of program
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
30 May, 2022
Like Article
Save Article