Monday, September 5, 2011

TASM Assembly Program to Find the Largest of N Numbers

The TASM Assembly program given can be used to find the largest number among the numbers entered to an array.The Complete Source Code is given Below.
 print macro msg  
  mov ah,09h  
  mov dx,offset msg  
  int 21h  
 endm  
 read macro num  
  mov ah,01h  
  int 21h  
  sub al,'0'  
  mov bh,0ah  
  mul bh  
  mov num,al  
  mov ah,01h  
  int 21h  
  sub al,'0'  
  add num,al  
 endm  
 data segment  
  cr equ 0dh  
  lf equ 0ah  
  msg1 db 'Enter the limit ',cr,lf,'$'  
  msg2 db cr,lf,'Enter the no:',cr,lf,'$'  
  msg3 db cr,lf,'$'  
  msg4 db cr,lf,'largest no is',cr,lf,'$'  
  num db ?  
  n db ?  
  arr db 100 dup(0)  
  larg db 8 dup('$')  
 data ends  
 code segment  
 assume cs:code,ds:data  
  start:mov ax,data  
     mov ds,ax  
     print msg1  
     read n  
     mov ch,00h  
     mov cl,n  
     mov si,00h  
     print msg2  
  rept1:read num  
     mov bl,num  
     mov arr[si],bl  
     inc si  
     print msg3  
     loop rept1  
     mov si,00h  
     mov ch,00h  
     mov cl,n-1  
     mov al,arr[si]  
  rept2:inc si  
     mov bl,arr[si]  
     cmp bl,al  
     jb exit  
     mov al,bl  
  exit:loop rept2  
     mov ah,00h  
     mov si,offset larg  
     call hextoasc  
     print msg4  
     print larg  
     mov ah,4ch  
     mov al,00h  
     int 21h  
 hextoasc proc near  
  push ax  
  push bx  
  push cx  
  push dx  
  push si  
  mov cx,00h  
  mov bx,0ah  
 rept3:mov dx,00  
    div bx  
    add dl,'0'  
    push dx  
    inc cx  
    cmp ax,0ah  
    jge rept3  
    add al,'0'  
    mov [si],al  
 rept4:pop ax  
    inc si  
    mov [si],al  
    loop rept4  
    inc si  
    mov al,'$'  
    mov [si],al  
    pop si  
    pop dx  
    pop cx  
    pop bx  
    pop ax  
    ret  
  hextoasc endp  
  code ends  
 end start  

No comments:

Post a Comment

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...