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


7 - The Pros and Cons

Compiling assembly code in this way gives us some advantages: we can use aliases for registers, there is no C function exit and entry code surrounding us, and we can return values. However, one disadvantage is that it can't be easily debugged. Code embedded in a C function can be viewed on the debugger and walked through, aiding development. The debugger also provides an excellent register display (although RPTR is a little hard to decipher), so you can watch the side effects as they occur.

The code is quite simple, since all it does is get the values pointed to, and compares them - the difference indicates which was larger. In a small function like this we don't need to save registers or create local variables, so the result is a very small and fast routine, excellent for speedy sorting.

Finally, to make it available to the C code, we add its prototype to the .CPP file, and wrap it in an extern to prevent name mangling:

  extern "C"
  {
    int ASM_Code_Compare(const void *ptrA,const void *ptrB);
  }


Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice