Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9237443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:32:11+00:00 2026-06-18T07:32:11+00:00

I want to write a 8086 assembly program that takes 5 strings from the

  • 0

I want to write a 8086 assembly program that takes 5 strings from the user as an input and then sorts these strings and prints the sorted result as an output. I actually do everything but I have a big problem with the sorting part. I know how to use a for example bubble sort to sort the items in an array that start from a specific address but here I have 5 different strings that are not in the same array. each string has its own address and its own characters. I try to compare last character of each string with each other and then if one is bigger that another one i swap the whole string and then I go on and do that for the whole characters of all string to the first.

For example if our input strings are:

eab    
abe    
cbd    
cda    
adb

I will first sort the last character of every string and I come up with this:

cda    
eab    
adb    
cbd    
abe

Then I will compare them by the middle character:

eab    
cbd    
abe    
cda    
adb

and at last with the first character and everything is sorted:

abe
adb
cbd
cda    
eab

but it is actually what in my mind and I don’t have any idea who to implement that for my job.

; multi-segment executable file template.

data segment 
    data1 db 64,?,64 dup(?)
    data2 db 64,?,64 dup(?)
    data3 db 64,?,64 dup(?)
    data4 db 64,?,64 dup(?)
    data5 db 64,?,64 dup(?)

    change db 66 dup(?)

    msg db 0ah,0dh,"You enter a wrong option",0ah,0dh,"try again",0ah,0dh,"$" 
    prompt db 0ah,0dh,"Choose an option:",0ah,0dh,"$"
    prompt1 db ".a: Sort in ascending order",0ah,0dh,"$" 
    prompt2 db ".d: Sort in descending order",0ah,0dh,"$"
    prompt3 db ".q: Quit",0ah,0ah,0dh,"$" 
    enter db 0ah,0ah,0dh,"Enter 5 strings:",0ah,0dh,"$"
    pkey db 0ah,0dh,"press any key...$"
ends

stack segment
    dw   128  dup(0)
ends

code segment
main proc far
; set segment registers:
    mov ax, data
    mov ds, ax
    mov es, ax

again:
; printing the prompts for the user
    lea dx, prompt
    mov ah, 09h
    int 21h   

    lea dx, prompt1
    mov ah, 09h
    int 21h

    lea dx, prompt2
    mov ah, 09h
    int 21h

    lea dx, prompt3
    mov ah, 09h
    int 21h   

; getting a character from the user as an input
    mov ah, 01h
    int 21h

; determining which option the user selects    
    cmp al, 'a'
    je ascending
    cmp al, 'd'
    je descending
    cmp al, 'q'
    je quit

; this is for the time that the user enters a wrong char    
    lea dx, msg
    mov ah, 09h
    int 21h
    jmp again     ; again calling the application to start

ascending:
    call input
    call AscendSort
    jmp again     ; again calling the application to start

descending:
    call input
    call DescendSort
    jmp again     ; again calling the application to start

quit:            
    lea dx, pkey
    mov ah, 9
    int 21h        ; output string at ds:dx

    ; wait for any key....    
    mov ah, 1
    int 21h

    mov ax, 4c00h ; exit to operating system.
    int 21h  
main endp
;.................................................
; this subroutine gets input from user
input proc

    lea dx, enter
    mov ah, 09h
    int 21h
    call newline

    mov ah, 0ah
    lea dx, data1
    int 21h      
    call newline

    mov ah, 0ah
    lea dx, data2
    int 21h
    call newline

    mov ah, 0ah
    lea dx, data3
    int 21h
    call newline

    mov ah, 0ah
    lea dx, data4
    int 21h
    call newline

    mov ah, 0ah
    lea dx, data2
    int 21h
    call newline

    ret 
input endp
;................................................
; sorting the strings in the ascending order
AscendSort proc         

    mov si, 65
    lea dx, change
    mov al, data1[si]
    cmp al, data2[si]
    ja l1    
    ?????

    ret
AscendSort endp 
;................................................
; sorting the strings in the descending order
DescendSort proc



    ret
DescendSort endp 
;................................................
; newline
newline proc

    mov ah, 02h
    mov dl, 0ah
    int 21h

    mov dl, 0dh
    int 21h   

    ret        
newline endp    
ends

end main ; set entry point and stop the assembler.

Any other algorithm for sorting these whole strings also will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:32:12+00:00Added an answer on June 18, 2026 at 7:32 am

    I actually figure out the answer myself, I use string commands to compare the strings 2 by 2 with each other to see if they’re bigger, smaller or equal. Something like the code below in the specific macro that takes two strings to check them and do the required operation like swapping the strings to make them sorted:

    check macro a, b
        local next, finish
        cld
        mov cx, 64  ; the size of our buffer that saves the string
        mov si, a
        mov di, b
    
        repe cmpsb  ; comparing two strings with each other
        ja next
        jmp finish
    
    next:
        ; swaping our strings if needed
        mov cx, 64
        mov si, a
        lea di, change
        rep movsb 
    
        mov cx, 64
        mov si, b
        mov di, a
        rep movsb
    
        mov cx, 64
        lea si, change
        mov di, b
        rep movsb 
    
    finish:
    
    endm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a program in Prolog that confirms if a b-tree of
I want write a program that when installed, runs in background and adds a
I want to write a Boost-Python program to take a symbolic python function from
I want to write 16 bit 8086 assembly code in visual studio 2010 but
I want to write 16 bit 8086 assembly code in visual studio 2010 but
I am developing a program that need read/write some files from sdcard or internal
I want write a simple query which will fetch data from a table (which
I want to write <a href=product.php?id=5> as product/5.I am not talking about user to
I want to write a program to contact a PHP script online, and show
I want write a small program to get IP Address of some websites by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.