×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Assembly Language Sort Code

Assembly Language Sort Code

Assembly Language Sort Code

(OP)
Hi, I need the code for a sort in assembly language.  I am not concerned with speed so
bubble sort is fine.  I have an array of 10 8-bit numbers that need sorting and I am trying to convert my C++ code of bubble sort to assembly language but am failing
miserably... Can anyone help me out?  I found this code on the net for 32-bit
numbers for a bubble sort but can't convert it to an 8-bit version... Thanks a lot!
caplan8293

;bubble sort for 32-bit
; by Andrew Howe
outerloop:  lea     ebx,[edi+ecx*4]
            mov     eax,[edi]
cmploop:    sub     ebx,4
            cmp     eax,[ebx]
            jle     notyet
            xchg    eax,[ebx]
notyet:     cmp     ebx,edi
            jnz     cmploop
            stosd
            loop    outerloop

RE: Assembly Language Sort Code

Have you tried using smaller registers when converting?  The eax register is 32 bits, so for 8 bits, it should probably be either ah or al, etc.  The registers in an intel chip look like this:
        eax
   ah         al
bbbbbbbb | bbbbbbbb, so depending on what you call the register, you get a certian number of bits.

Also, you're comparing with a value that is in memory, so you need to watch out for it being big-endian, you need to check on that.  If it's borland, you should be ok.  Good Luck!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close