Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assembly Language Sort Code

Status
Not open for further replies.

caplan8293

Programmer
Sep 13, 2000
7
0
0
US
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
 
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top