Author Topic: i need use the quicksort function nrQsortA do you have some example  (Read 7004 times)

jlopezs104

  • Guest
hi i´m in a trouble with a homework about the quicksort function in masm32 if you have a some example i will thank you a lot. i saw a threads with examples here but i can't see that.

BogdanOntanu

  • Global Moderator
  • Member
  • *****
  • Posts: 69
    • Solar_OS, Solar_Asm and HE RTS Game
Re: i need use the quicksort function nrQsortA do you have some example
« Reply #1 on: June 07, 2012, 07:55:52 AM »
There is a "no homework" requests rule in those forums...

Show us what you did and we might help you do your own work.

Please do not ask us to do the homework for you  :icon_mrgreen:
Ambition is a lame excuse for the ones not brave enough to be lazy, www.oby.ro

jlopezs104

  • Guest
Re: i need use the quicksort function nrQsortA do you have some example
« Reply #2 on: June 07, 2012, 08:48:59 AM »
Sorry i'm new in the forums my program is this:
.386
      .model flat, stdcall
     .STACK 64;16
      option casemap :none   ; case sensitive
 .nolist
      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \masm32\include\masm32.inc
    
 .list
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \masm32\lib\masm32.lib
      includelib \masm32\lib\oleaut32.lib
    .data
    arreglob db 1,4,2
   
    .code
    start:
    mov esi,OFFSET arreglob
   mov al,[esi]
   inc esi
   inc ecx
   mov al,[esi]
   ;mov arreg[esi]
   invoke ClearScreen
   
   
   INVOKE  nrQsortA,offset arreglob,3
   invoke locate,10,10
   invoke StdOut,ADDR arreglob
   
   
   invoke ExitProcess,0
    end start

i dont now what is the problem because the program dont print

P.D sorry for my english i'm latinamerican and my english is poor

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: i need use the quicksort function nrQsortA do you have some example
« Reply #3 on: June 07, 2012, 10:06:58 AM »
remove the .STACK directive for Flat models

if you are going to INCLUDELIB oleaut32.lib, you should also INCLUDE oleaut32.inc
i don't think either is needed, in this case

Code: [Select]
    arreglob db 1,4,2i am pretty sure the routine is designed to sort DWORD's - not BYTE's
Code: [Select]
    arreglob dd 1,4,2
you have binary values in the array - not ASCII values
so - to diplay them you will want to convert them to ASCII decimal or ASCII hexidecimal (probably) strings
then display them
also - displayed strings should be zero-terminated

jlopezs104

  • Guest
Re: i need use the quicksort function nrQsortA do you have some example
« Reply #4 on: June 07, 2012, 12:30:15 PM »
Many thanks for your help dedndave I will do what you tell me and hopefully make my program work fine

Thanks a lot  :biggrin: :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8893
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: i need use the quicksort function nrQsortA do you have some example
« Reply #5 on: June 07, 2012, 02:22:07 PM »
Just note that "nrQsortA" is designed to sort DWORD sized numbers where your example is trying to sort byte sized data. If you need to sort byte data you either need to do some conversions or write a different algorithm. If you are required just to sort numbers, use DWORD sized data and any of the numeric sorts will work fine for you.


Code: [Select]
    myarray dd 10,9,8,7,6,5,4,3,2,1

When you call an array sort procedure you pass the address of the array, in this instance "OFFSET myarray" and you pass the count of array members, in this instance 10.

The advantage of using DWORD over BYTE is DWORD has a 4 billion number range where BYTE on has 256.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2613
Re: i need use the quicksort function nrQsortA do you have some example
« Reply #6 on: June 08, 2012, 04:12:59 AM »
Hi jlopezs104,

Here is a quick example :

Code: [Select]
include     \masm32\include\masm32rt.inc

NUMB_OF_MEMBERS equ 10


.data

array       dd 80,95,100,70,60,72,30,10,20,5
msg         db 'Member %d = %d',13,10,0


.code

start:

    call    main
    invoke  ExitProcess,0

main PROC uses esi ebx

    mov     esi,OFFSET array
    invoke  nrQsortA,esi,NUMB_OF_MEMBERS
    mov     ebx,1
@@:   
    invoke  crt_printf,ADDR msg,ebx,DWORD PTR [esi]
    add     ebx,1
    add     esi,4
    cmp     ebx,NUMB_OF_MEMBERS+1
    jnz     @b
    ret

main ENDP

END start

jlopezs104

  • Guest
Re: i need use the quicksort function nrQsortA do you have some example
« Reply #7 on: June 08, 2012, 07:00:54 AM »
thanks for your help with your example finished understand how the arrangement and function quicksort and the other sorting functions :biggrin: :biggrin: :biggrin: you saved my life