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

  • Home
  • SEARCH
  • 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 3314756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:16:13+00:00 2026-05-17T22:16:13+00:00

I’m trying to write in assembly language a function sort. It will sort the

  • 0

I’m trying to write in assembly language a function sort. It will sort the two dimensional array such that the rows will now contain data in alphabetical order.
I have tried many things but it is honestly beyond my current knowledge.
here’s what I tried so far…

.386
public _Sort
.model flat
.code
_Sort proc

    push ebp
    mov ebp, esp
    push esi
    push edi

    mov edi, [esp + 4]    ; address of destination array
    mov esi, [esp + 8]    ; address of source array
    mov ecx, [esp + 16]   ; # of elements to mov
    cld
    rep movsd
L1:
    mov eax, [esi]
    cmp [esi + 8], eax
    jg L2
    xchg eax, [esi + 8]
    mov [esi], eax
L2: 
    pop edi
    pop esi
    pop ebp

    ret     
_Sort endp
end

Here’s the C++ code…

#include <iostream>

using namespace std;

extern "C" int Sort (char [] [20], int, int);

void main ()
    {
    char Strings [10] [20]
                    = { "One",
                        "Two",
                        "Three",
                        "Four",
                        "Five",
                        "Six",
                        "Seven",
                        "Eight",
                        "Nine",
                        "Ten"   };
    int i;
    cout << "Unsorted Strings are" << endl;
    for (i = 0; i < 10; i++)
        cout << '\t' << Strings [i] << endl;
    Sort (Strings, 10, 20);
    cout << "Sorted Strings are" << endl;
    for (i = 0; i < 10; i++)
        cout << '\t' << Strings [i] << endl;
    }

I do realize my assembly does not make sense, sorry about that.

  • 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-05-17T22:16:14+00:00Added an answer on May 17, 2026 at 10:16 pm

    You’ll want to build your assembly code in functions/procedures, just like you would code in some other language. Much like in C, string comparison, copying, etc., will need to be done in functions. Just for example:

    ; compares [esi] to [edi], returns +, 0 or - to indicate order
    ; inputs: esi, edi: addresses of strings
    ; destroys: esi, edi, edx
    ;
    strcmp_int proc
        jmp short start
    loop_top:
        inc esi
        inc edi
    start:
        movsx eax, byte ptr [esi]
        movsx edx, byte ptr [edi]
        test edx, edx
        jz @f
        sub eax, edx
        jz loop_top
        ret
    @@:
        sub eax, edx
        ret
    strcmp_int endp
    

    [warning: this code isn’t necessarily intended to be used as-is–just an example of one of the kinds of functions you’ll normally need to write to do this sort of job in assembly language. It’s been long enough since I wrote much assembly language that you can undoubtedly do better on a modern processor–and at least for things done purely in assembly language, you normally want to put results in flags, rather than a -/0/+ in a register like strcmp (and this) produce. But note that this does return with flags set by the final sub]

    See also Why is memcmp so much faster than a for loop check? for some links to optimized implementations (SSE2/AVX2) for explicit-length strings, which can be much faster for medium to long strings. For optimization links in general, see the x86 tag wiki.

    Your sort will depend on the sorting algorithm you decide to implement. Obviously, a Quicksort won’t look the same as an insertion sort. The main point, however, is simple: don’t try to write it as a single, monolithic chunk of code—break it up into pieces that are individually easy to write and understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.