News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

array masm 32

Started by imadhx30, December 20, 2013, 06:56:11 AM

Previous topic - Next topic

imadhx30

Hello,
how to sort an array masm 32?
:dazzled:

jj2007

For string arrays, check \Masm32\help\masmlib.chm, in particular Comb Sort, Quick Sort etc; see also QSort

For numeric arrays, see nrQsortA (masmlib.chm, DWORDs only) or ArraySort (DWORD, QWORD, REAL4, REAL8).

Attached a testbed comparing Masm32 and MasmBasic arrays. Slightly worrying that they don't come to identical sort results, but maybe I've misunderstood something ::)

MasmBasic:
2891    us for Recall   31980 us for sorting L$
2798    us for Recall   32033 us for sorting L$
2801    us for Recall   33059 us for sorting L$
2813    us for Recall   32435 us for sorting L$
2785    us for Recall   33147 us for sorting L$

Masm32:
19119   us for arrfile$ 2183 us for sorting arrfile$
16871   us for arrfile$ 2065 us for sorting arrfile$
17582   us for arrfile$ 2059 us for sorting arrfile$
17070   us for arrfile$ 2057 us for sorting arrfile$
17999   us for arrfile$ 2057 us for sorting arrfile$

26902 vs 26902 elements

Elements 10000 to 10002, MasmBasic:
10000   CMIC_MASK_ASYNCOK       equ SEE_MASK_ASYNCOK
10001   CMIC_MASK_FLAG_NO_UI    equ SEE_MASK_FLAG_NO_UI
10002   CMIC_MASK_FLAG_SEP_VDM  equ SEE_MASK_FLAG_SEPVDM

Elements 10000 to 10002, Masm32:
10001     tmDefaultChar         BYTE      ?
10002     tmBreakChar           BYTE      ?
10003     tmItalic              BYTE      ?

The attached exe creates two text files with a sorted Windows.inc. Note that for both methods, the first 1681 (Masm32) resp 1688 (MasmBasic) lines are empty strings.

jj2007

Quote from: jj2007 on December 20, 2013, 09:57:49 AM...comparing Masm32 and MasmBasic arrays. Slightly worrying that they don't come to identical sort results, but maybe I've misunderstood something ::)

I'm a bit lost. The problem is that nrQsortA is not the right function, it sorts the addresses, not the strings. But the string sort, which seems to be assort, does not work, it crashes with an exception ::)

So what is the correct way of loading Windows.inc into an array and sorting the strings?

   if 0
      dec arrcnt$(hArray)
      invoke assort, hArray, eax, 9   ; rdi not explained...
   else
      invoke nrQsortA, hArray, arrcnt$(hArray)   ; works but simply sorts the addresses as DWORDs
   endif

dedndave

create an array of string addresses
sort the array by string
compose a new compilation of strings according to the array

is that what you're looking for ?

jj2007

Quote from: dedndave on December 21, 2013, 05:14:59 AM
create an array of string addresses
sort the array by string
compose a new compilation of strings according to the array

is that what you're looking for ?
That is damn easy:
   Recall "\Masm32\include\Windows.inc", My$()
   QSort My$()

No, I was looking for the official Masm32 way of doing it. It seems that assort is supposed to do that, but whatever I try, I get tried, I got an exception :(

But I cracked the mystery - some acrobacy needed (thanks, Olly :P):

   mov esi, hArray
   add esi, 4   ; :eusa_dance:
   invoke assort, esi, arrcnt$(hArray), 0   ; rdi is nowhere explained...

Output:
MasmBasic:
2855    us for Recall   32258 us for sorting L$
2932    us for Recall   32290 us for sorting L$
3269    us for Recall   32026 us for sorting L$
2839    us for Recall   40253 us for sorting L$
2808    us for Recall   32096 us for sorting L$

Masm32:
16706   us for arrfile$ 28549 us for sorting arrfile$
16783   us for arrfile$ 28297 us for sorting arrfile$
16804   us for arrfile$ 28378 us for sorting arrfile$
16721   us for arrfile$ 28196 us for sorting arrfile$
16741   us for arrfile$ 28967 us for sorting arrfile$

First non-empty strings, MasmBasic:
1687                        BYTE 64 dup (?)
1688                        WORD 64 dup (?)
1689                    Dimension dw 4 dup(?)
1690                    Linenumber dw ?
1691                    PointerToLinenumber dd ?
1692                    PointerToNextFunction dd ?
1693                    Size1 dw ?
1694                   ends
1695                   ITEMTYPE <>
1696                  --------------------------------------------- *

First non-empty strings, Masm32:
1687                        BYTE 64 dup (?)
1688                        WORD 64 dup (?)
1689                    Dimension dw 4 dup(?)
1690                    Linenumber dw ?
1691                    PointerToLinenumber dd ?
1692                    PointerToNextFunction dd ?
1693                    Size1 dw ?
1694                   ITEMTYPE <>
1695                   ends
1696                  --------------------------------------------- *

imadhx30

in masm32 http://website.assemblercode.com/masm32/masm32v11r.zip

jj2007

Hi imadhx30,

It doesn't make your link more valuable if you post it in two different threads. Besides,
a) posting the same stuff twice is considered a bad habit,
b) the only legitimate source for the masm32v11r.zip file is here, on this site.

Check the downloads section in the upper right corner. And, by the way, welcome to the Forum :icon14:

imadhx30

Write a program that allows masm32 to sort an array
keyboard input!!!! :icon_exclaim:

The problem solution from libraries
include\masm32\include\kernel32.inc
include\masm32\include\masm32.inc
include\masm32\include\msvcrt.inc
includelib\masm32\lib\kernel32.lib
includelib\masm32\lib\masm32.lib
includelib\masm32\lib\msvcrt.lib

jj2007

Study \Masm32\examples\exampl06\bubble\bubble.asm

dedndave

also, the input() macro, used for getting user input from the keyboard
the sval() macro for converting signed strings to 32-bit binary
the uval() macro for converting unsigned strings to 32-bit binary

if the array index is in EDI....
    mov     MyArray[4*edi],uval(input("enter a number: "))
gets an unsigned user value, converts it to 32-bit binary, and stores it in the array