0

Following is the code for finding the minimum and maximum of array elements in assembly language , compiled using tasm. But the issue is it is running for only single digit sized array , like it is only numbers till 9 not more than that. I want to run the code for for array size=99. I dont know how to handle two digit sized array. Also it should accept double digit sized elements like 34 , 22 etc. Right now it is only accepting elements 0-9.

.model small
.386p
.stack
.data

    ARRAY db 10 dup(?)

    msg0 db 13,10,"ENTER NO.:$"
    msg1 db 13,10,"ENTER NUMBER OF ELEMENTS:$"
    msg2 db 13,10,"MAX:$"
    msg3 db 13,10,"MIN:$"

    n db ?
    max db 00H
    min db 00H
    first db 01H

.code

start:

    mov eax,@data
    mov ds,eax
    
    mov dx,offset msg1
    mov ah, 09H
    int 21H
    mov ah,01H
    int 21H
    mov n,al
    sub n,30H
    mov cl,n
    
INPUT:
    mov dx,offset msg0
    mov ah,09H
    int 21H
    
    mov ah,01H
    int 21H
    
    mov bl,first
    cmp bl,01H
    jnz minset
    mov first,00h
    mov min,al

minset:

    sub al,30H

    mov bl,max
    cmp bl,al

    ja nomax

    mov max,al
nomax:
    
    mov bl,min
    cmp bl,al

    jb nomin

    mov min,al

nomin:

    mov ARRAY[si],al
    inc si
    LOOP INPUT
    
    mov si,0
    mov cl,n
    
print:
    mov dx,offset msg2
    mov ah, 09H
    int 21H

    mov dl,max
    add dl,30H
    mov ah,02H
    int 21H
    
    mov dx,offset msg3
    mov ah, 09H
    int 21H


    mov dl,min
    add dl,30H
    mov ah,02H
    int 21H
    

EXIT:
end start
end


  • 1
    Your problem isn't arrays, it's input of multi-digit numbers. (Of course, with fixed size `db 10 dup(?)`, entering a larger number will overflow that fixed buffer.) – Peter Cordes Dec 03 '20 at 05:16
  • So how to handle multi digit numbers , because if i try to input multidigit number , it does not accept it . after typing First number it just transfer itself to the next line. – Maninder kaur Kathuria Dec 03 '20 at 05:20
  • 1
    [NASM Assembly convert input to integer?](https://stackoverflow.com/q/19309749) shows how for NASM, should be easy to implement the same algorithm in 16-bit NASM with only minor changes to the code. That's why I already closed it as a duplicate, see the link at the top of the page. – Peter Cordes Dec 03 '20 at 05:21

0 Answers0