home | |||
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 |
6 - Some Assembly RequiredThe ASM compare function operates the same as the C, but of course faster - qsort() is sped up by about 25%:ASM_Code_Compare ; prototype: ; ; int ASM_Code_Compare(const void *ptrA,const void *ptrB); ; ; equivalent to: ; ; return *((unsigned long*)ptrA) - *((unsigned long*)ptrB); ; ; compare two longs pointed to by pointers in r0, r1 ; we use r2 and r3 for workspace, and need no other ; registers, so no pushing ; mov r1,t ; get long value pointed to by r1 mov32 (t),r2 ; and save in r2 mov r0,t ; get long value pointed to by r0 mov32 (t),r3 ; save into r3-but we really only need t's value rptr r2 sub rp ; subtract the two mov t,r0 ; place result in r0 for return rtsThe format may appear odd, since this is assembly code in its natural state, not as part of a C function. To code in this way, the source was created as the file 'func.s', and the makefile modified to compile it: SRCS_CPP = eg_12.cpp eg_12_form.cpp SRCS_C = SRCS_S = func.s Previous Section Next Section |
||
Copyright © 2001-2006 ebmDevMag.com - Legal Notice |