NO

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

Offline Vortex

  • Member
  • *
  • Posts: 518
    • 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...