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:
- Start
- Initialize data segment through AX register in
the DS register.
- Initialize the SI to 5000h
- Initialize total elements of array as a count
in CX(e.g 0005h)
- Preserve the above count in c temporary
variable.
- Display the message as “Enter an array
elements”
- Read first digit in AL register through
keyboard (e.g. AL=31h)
- Call Input procedure to make a number from
ASCII hexadecimal to a normal hexadecimal number.AL=01h
- Move AL
contents to BL
- Rotate BL
contents by 4 in left direction.
- Read second
digit in AL register through keyboard (e.g AL=32h)
- Call Input procedure to make a number from
ASCII hexadecimal to a normal hexadecimal number.AL=02h
- Add BL and
AL contents (BLß
BL+AL)
- Store the
BL (current accepted number) to
location pointed by SI
- Increment
SI by 1 to point to next location for the next number
- Repeat step
no. 7 to 15 till CX count reaches to 0.
- Initialize
SI again to 5000h and CX also with
total number of elements.
- Initialize
AL with first element pointed by SI for the next comparison
- Compare
number pointed by SI from an array with AL register
- If carry is
generated (i.e. if number in AL > number pointed by SI) then goto step
no. 22 else goto step no. 21
- Make a unconditional jump to step no. 23
- Move number
pointed by SI to AL
- Incremented
SI by 1
- Decrement
CX by 1
- Compare CX
with 0000h (i.e. Repeat step no.19 to 25 till all numbers of array are not
covered for the comparison)
- If Zero
flag is not set then jump to step no.19
- Finally
minimum number will be available in AL register.
- Display the
contents of AL register.
- Stop.
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 Startoutput:-
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: