• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

x86 asm -> inline C++ asm?

xtknight

Elite Member
I want to use the code here in my C++ program.

I'm using the MS VC++ 2005 Express compiler. However, I have little to no experience with x86 asm. How would I insert the asm into my program and call the asm procedure? Does the fact that it's 'MASM' (vs. another ASM?) make any difference in my situation?

Will the asm dword sorting code also allow me to sort integers (unsigned)?

Thanks.
 
void bs(void * array, unsigned int len) {
__asm {
; insert assembly here
}
}

the code only allows sorting unsigned integers.. if you want to sort integers, change the "jb @@" instruction to "jl @@"


anyways, it doesn't really seem like you're trying to learn assembly, and if performance were really a concern, you wouldn't be using bubblesort in the first place. so then why..?? if something goes wrong you're gonna have one hell of a headache.
 
Thanks for the example (I can likely figure out how to implement any asm now). The main reason I'm using bubble sort is 'cause that's the only ASM code for sorting on that site. I wanted to see if bubble sort in ASM was faster than insertion sort in C. I'm just trying to find the fastest sort I can for integers. I'm just sorting a list of years (1975, 1976, etc) so they will all be positive but they are still stored in an 'int' (signed I assume). It would be easy to make them unsigned though.

If you want more context, what I'm really doing is 'clumping' together years with the same value to create ranges. Much easier to explain with examples:

(year)::value

input1(string array):
"1975::5"
"1976::5"
"1977::5"

output1(string array): "1975-1977::5"

input2(string array):
"1976::06"
"1975::05"
"1977::06"
"1978::07"

output2(string array):
"1975::05"
"1976-1977::06"
"1978::07"

It first sorts the years, then it finds like values and creates a range of like years.

I managed to make a program in visual basic to do it reliably...I'm going to convert that to C now and I'm replacing the C sort algorithm (which is one part of the clumping function) with an asm one. The rest is still in C and it would be way over my head to make asm code for it.

I need to treat the second value (e.g. "1975::05") as a string (the zero in 05 is preserved, not truncated to 5) so I need a string sort algorithm as well.
 
Is part of the problem a large data set size? Because the algorithms are classically organized by performance over very large data sets. Small data sets are probably best addressed in this manner. For large data sets, using the built-in quicksort or a variant would be better.
 
Well, I am doing about 400 sets of 30 of these year/value sets. This isn't the part of my program that's taking the longest (to my knowledge), though I'd like to make it as fast as possible anyway. What do you mean by "built-in" QuickSort?
 
Back
Top