News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Is "array_create" procedure run away?

Started by zjw, July 29, 2009, 12:03:14 AM

Previous topic - Next topic

zjw

Where is the source file of array_create procedure?
I can't find it in masm32lib directory!


zjw

Oh, I know, thank you very much.
I just want to learn the algorithm and study every procedure in m32lib.

hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php


dedndave

oh - he was looking for array_create - that is not the same as create_array - lol

hutch--

Here is a variation that only does one allocation that contains both the array of pointers and the data pointed to by the array.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

    align 16

fixed_alloc proc cnt:DWORD,blen:DWORD

    movd mm0, esi
    movd mm1, edi

    mov edi, [esp+8]

    add edi, 3                      ; align blen up to next 4 byte boundary
    and edi, -4


    mov esi, [esp+4]
    add esi, esi                    ; mul cnt by 4
    add esi, esi                    ; store pointer array length in ESI
   
    mov ecx, [esp+4]                ; calculate length required
    mov eax, edi
    imul ecx                        ; multiply cnt by blen to get data storage size
    add eax, esi                    ; add pointer array length

    push eax
    push GMEM_FIXED or GMEM_ZEROINIT    ; allocate fixed memory
    call GlobalAlloc

    mov edx, eax                    ; store memory address in EDX
    mov ecx, eax
    add ecx, esi                    ; add the length of the pointer array to ECX

    mov esi, [esp+4]
  align 4
  @@:
    mov [eax], ecx                  ; write each data storage member to pointer array
    add eax, 4                      ; next pointer
    add ecx, edi                    ; add blen for next data storage
    sub esi, 1
    jnz @B

    mov eax, edx                    ; return the memory start address

    movd esi, mm0
    movd edi, mm1

    ret 8

fixed_alloc endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zjw

Thanks, hutch. But, I know little about movd and mm0, mm1, I could not use them.

hutch--

Enaqble MMX with the ".MMX" directive at the beginning of your code. Put it AFTER the .486 and change that to .686p .
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zjw

Just like this?

.486
.686p
.mmx
.model flat, stdcall
option casemap :none

...

hutch--

You can leave out the first .$*^ as you are specifying a higher processor with the .686p.


.686p
.mmx
.model flat, stdcall
option casemap :none
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zjw