Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to accept N names from the user and sort them in descending order

Posted By: Harrison Evans     Category: Assembly Language     Views: 5479

Write an assembly program to accept N names from the user and sort them in descending order.

Code for Program to accept N names from the user and sort them in descending order in Assembly Language

.model small

.data
        strarry db 'act'
                db 'art'
                db 'dog'
                db 'cat'
                db 'ant','$'
        strlen  db 3
        tmpSi dw ?
        tmpDi dw ?
        tmp db 3 dup(' ')
        cnt1 db 1
        cnt2 db 0

.code
        mov ax,@data
        mov ds,ax
        mov es,ax

        mov SI,00
        mov DI,00
        mov BX,00

        outer:
                LEA SI,strarry[BX]
                mov tmpSi, SI
                mov DI,SI
                add DI,3
                mov dh,cnt1
                mov cnt2,dh
                inner:
                        mov cx,3
                        mov tmpDi,DI
                        repe CMPSB
                        jl swap
                        add cnt2,1
                        cmp cnt2,5
                        je incbx

                        add tmpDi,3
                        mov DI,tmpDi
                        mov SI,tmpSi
                        jmp inner


                        incbx:
                                add cnt1,1
                                cmp cnt1,5
                                je ext
                                add BX,3
                                add cnt2,1
                                jmp outer
                                jmp ext

                       swap:
                                mov cx,3
                                mov SI,tmpSi
                                LEA DI,tmp
                                rep MOVSB
                
                                mov cx,3
                                mov SI,tmpDi
                                mov DI,tmpSi
                                rep MOVSB

                                mov cx,3
                                mov DI,tmpDi
                                LEA SI, tmp
                                rep MOVSB

                                add cnt2,1
                                cmp cnt2,5
                                je incbx
                                add tmpDi,3
                                mov DI,tmpDi
                                mov SI,tmpSi
                                jmp inner

               ext:
                mov ax,0900h
                LEA DX,strarry
                int 21h
                mov ax,4C00h
                int 21h
end
  
Share: 



Harrison Evans
Harrison Evans author of Program to accept N names from the user and sort them in descending order is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Assembly Language:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!