Program Of Sorting In 8086

Posted on by admin

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 actually figure out the answer myself, I use string commands to compare the strings 2 by 2 with each other to see if their bigger, smaller or equal. Something like the code below in the specific macro that takes two strings to checks them and do the required operation like swapping the strings to make them sorted: check macro a, blocal next, finishcldmov cx, 64; the size of our buffer that saves the stringmov si, amov di, brepe cmpsb; comparing two strings with each otherja nextjmp finishnext:; swaping our strings if neededmov cx, 64mov si, alea di, changerep movsbmov cx, 64mov si, bmov di, arep movsbmov cx, 64lea si, changemov di, brep movsbfinish:endm.

You'd probably get better results from just using a compiler. Normally you sort strings by sorting an array of pointers. So the swaps just swap pointers, not the whole strings.

Program Of Sorting In 8086 C

Number sorting program

Your solution works (slowly) when all the strings are the same size. If you need to actually sort the string storage locations, it would be faster to sort pointers, and then put all the strings in order, so the actual string data would only be copied once.

Also, you can save an instruction by doing jna finish, instead of ja next / jmp finish.–Oct 2 '15 at 8:14.

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 actually figure out the answer myself, I use string commands to compare the strings 2 by 2 with each other to see if their bigger, smaller or equal. Something like the code below in the specific macro that takes two strings to checks them and do the required operation like swapping the strings to make them sorted: check macro a, blocal next, finishcldmov cx, 64; the size of our buffer that saves the stringmov si, amov di, brepe cmpsb; comparing two strings with each otherja nextjmp finishnext:; swaping our strings if neededmov cx, 64mov si, alea di, changerep movsbmov cx, 64mov si, bmov di, arep movsbmov cx, 64lea si, changemov di, brep movsbfinish:endm. You'd probably get better results from just using a compiler. Normally you sort strings by sorting an array of pointers. So the swaps just swap pointers, not the whole strings. Your solution works (slowly) when all the strings are the same size.

If you need to actually sort the string storage locations, it would be faster to sort pointers, and then put all the strings in order, so the actual string data would only be copied once. Also, you can save an instruction by doing jna finish, instead of ja next / jmp finish.–Oct 2 '15 at 8:14.