NO

Author Topic: Quicksort function from Pelles C run-time library  (Read 1876 times)

Offline Vortex

  • Member
  • *
  • Posts: 543
    • http://www.vortex.masmcode.com
Quicksort function from Pelles C run-time library
« on: October 13, 2019, 11:40:34 am »
Here is a Quicksort example employing Pelles C run-time library :

Code: [Select]
include Sample.inc

CompareProc PROTO C :DWORD,:DWORD

NUMB_OF_ELEMENTS equ 10

.data

numbers     dd 29,12,32,65,58,7,12,11,11,97
format1     db '%d',13,10,0

.code

start:

    invoke  qsort,ADDR numbers,\
            NUMB_OF_ELEMENTS,\
            SIZEOF DWORD,ADDR CompareProc

    call    PrintArray

    invoke  ExitProcess,0
   
CompareProc PROC C arg1:DWORD,arg2:DWORD

    mov     ecx,arg1
    mov     edx,arg2
    mov     eax,DWORD PTR [ecx]
    sub     eax,DWORD PTR [edx]
    ret

CompareProc ENDP

PrintArray  PROC uses esi ebx

    mov     ebx,NUMB_OF_ELEMENTS
    mov     esi,OFFSET numbers
@@:
    invoke  printf,ADDR format1,\
            DWORD PTR [esi]

    add     esi,4
    dec     ebx
    jnz     @b
    ret

PrintArray ENDP

END start
Code it... That's all...

Offline Grincheux

  • Member
  • *
  • Posts: 156
  • Never be pleased, always improve
    • Arachne
Re: Quicksort function from Pelles C run-time library
« Reply #1 on: April 19, 2021, 10:27:56 am »
I have created my own for Pelle's C

Code: [Select]

extern int CompareQSortProc(const void *__lpszArg1,const void *__lpszArg2) ;

CompareQSortProc   PROC   __lpszArg1:QWORD,__lpszArg2:QWORD
               mov      eax,DWORD PTR [rcx]
               sub     eax,DWORD PTR [rdx]
               ret
CompareQSortProc   ENDP


-------------------------
Kenavo / Bye