ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7
part 8
part 9


4 - Demo Code

This column's code is another example of assembly code, but with a twist - the code is actually slower than its C counterpart! In order to show function calling, I decided to use a sort with function parameter passing (like the Standard Library's qsort). Although slow, this sort has the advantage of being easier to read and understand, and (most importantly!) code.

The demo program performs any of six sort operations, first displaying a list of random numbers, sorting it, and then displaying the result. You can adjust the total items to sort so as to get an idea of relative performance.

The reason sorting was chosen to show function calling is related to the qsort function:

  void qsort( void *base, 
              size_t nelem, 
              size_t width, 
              int (_USERENTRY *fcmp)(const void *, const void *));
qsort() is passed a pointer to an array (which can be structs, pointers, integers, or whatever), a count of elements, and the size of an individual element. The last parameter is a function pointer (not a function call) to a comparison function. This function is passed pointers to two array elements, and returns a signed value indicating which is greater. You decide how to interpret the items in the passed function, which means you have great flexibility as to how to sort your list.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice