TASM Program to find minmum element in array

On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
Objective:
Write a assembly language code to find the minimum number from an array
Prerequisite:
TASM assembler
Algorithm:

  1. Start
  2. Initialize data segment through AX register in the DS register.
  3. Initialize the SI to 5000h
  4. Initialize total elements of array as a count in CX(e.g 0005h)
  5. Preserve the above count in c temporary variable.
  6. Display the message as “Enter an array elements”
  7. Read first digit in AL register through keyboard          (e.g. AL=31h)
  8. Call Input procedure to make a number from ASCII hexadecimal to a normal hexadecimal number.AL=01h
  9. Move AL contents to BL
  10. Rotate BL contents by 4 in left direction.
  11. Read second digit in AL register through keyboard (e.g AL=32h)
  12. Call Input procedure to make a number from ASCII hexadecimal to a normal hexadecimal number.AL=02h
  13. Add BL and AL contents (BLß BL+AL)
  14. Store the BL (current accepted  number) to location pointed  by SI
  15. Increment SI by 1 to point to next location for the next number
  16. Repeat step no. 7 to 15 till CX count reaches to 0.
  17. Initialize SI again to  5000h and CX also with total number of elements.
  18. Initialize AL with first element pointed by SI for the next comparison
  19. Compare number pointed by SI from an array with AL register
  20. If carry is generated (i.e. if number in AL > number pointed by SI) then goto step no.  22  else goto step no. 21
  21. Make  a unconditional jump to step no. 23
  22. Move number pointed by SI to AL
  23. Incremented SI by 1
  24. Decrement CX by 1
  25. Compare CX with 0000h (i.e. Repeat step no.19 to 25 till all numbers of array are not covered for the comparison)
  26. If Zero flag is not set then jump to step no.19
  27. Finally minimum number will be available in AL register.
  28. Display the contents of AL register.
  29. Stop. 
TASM Program :
Data Segment
 msg db 0dh,0ah,"Please enter the length of the array: $"
 msg1 db 0dh,0ah,"Enter a number: $"
 newl db 0dh,0ah," $"
 res db 0dh,0ah,"The minimum is: $"
 len db ?
 min db ?
Data ends
Code Segment
assume CS:Code,DS:Data
Start:
 mov ax,Data
 mov DS,ax

 mov dx,offset msg
 mov ah,09h
 int 21h
 
 call Accept

 mov len,bl
 mov cl,bl
 mov ch,00h

 mov di,1000h
 
back: mov dx,offset msg1
 mov ah,09h
 int 21h
 call Accept
 mov [di],bl
 inc di
 loop back

 mov di,1000h
 mov cl,len
 mov ch,00h

 mov dx,offset newl
 mov ah,09h
 int 21h

 mov al,[di] 
 mov min,al

chk: mov bl,min
 mov al,[di]
 cmp bl,al
 jc a
 mov min,al
 jmp b
a: mov min,bl
b: inc di
 loop chk

 mov dx,offset res
 mov ah,09h
 int 21h

 mov bl,min
 call DispNum

 mov ah,4ch
 int 21h
Accept proc
 mov ah,01h
 int 21h
 call AsciiToHex
 rol al,4
 mov bl,al
 mov ah,01h
 int 21h
 call AsciiToHex
 add bl,al
 ret
endp
DispNum proc
 mov dl,bl
 and dl,0f0h
 ror dl,4
 call HexToAscii
 mov ah,02h
 int 21h
 mov dl,bl
 and dl,0fh
 call HexToAscii
 mov ah,02h
 int 21h
endp
AsciiToHex proc
 cmp al,41h
 jc sk
 sub al,07h
sk: sub al,30h
 ret
endp
HexToAscii proc
 cmp dl,0ah
 jc sk2
 add dl,07h
sk2: add dl,30h
 ret
endp
Code ends
end Start
output:-
C:\TASM\BIN>tasm min.asm
Turbo Assembler  Version 4.1  Copyright (c) 1988, 1996 Borland International

Assembling file:   min.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  453k

C:\TASM\BIN>tlink min.obj
Turbo Link  Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International
Warning: No stack

C:\TASM\BIN>min

Please enter the length of the array: 05
Enter a number: 36
Enter a number: 12
Enter a number: 99
Enter a number: FF
Enter a number: 81

The minimum is: 12
--------------------------------

0 comments: