News:

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

How do i Declarie a ByteArray using proc Params

Started by T3kk, September 19, 2011, 04:26:47 PM

Previous topic - Next topic

T3kk

Hi,

I am trying to write a reall simple Dll which is given 2 peices of information as params,
the params are a long and byte

the proc then declares a bytearray with the long as the number of elements in the array and the byte is used to initialise the bytearray elements to that value.

However, this is not happening as I would have expected - The code I have is...

.386

.MODEL flat,stdcall

OPTION CASEMAP:NONE

Include windows.inc
Include user32.inc
Include kernel32.inc

IncludeLib user32.lib
IncludeLib kernel32.lib

.DATA

AppName db "ByeArrayLibrary",0
Copyright db "(C)Copyright 2011 CCS LABS and T3kk davesama@hotmail.co.uk",0

.code
DllEntry proc hInstance:HINSTANCE, reason:DWORD, reserved1:DWORD
.if reason==DLL_PROCESS_ATTACH
; start up proceedures
.elseif reason==DLL_PROCESS_DETACH
; close down proceedures
.endif
mov  eax,TRUE
ret
DllEntry Endp

; See skeleton.def: This is an exported function

; Param1 = size of the array
; Param2 = fill the array with what?
ReturnBytes proc  Param1:DWORD , Param2:DWORD
           
            ret
           
            DATA    SEGMENT PUBLIC 'DATA'
                        ByteArray       DB  Param1  DUP (Param2)   ; this variable is the first of 8 bytes
            DATA    ENDS
           
ReturnBytes    endp



End DllEntry


However I get a: error A2026: constant expected on the ByteArray definition
Any ideas

Be gentle - Im a total noob at asm :P
Cheers

qWord

The size of memory in the .data, .data? and .const section must be known at assembly time. What you are trying to do,is dynamic memory allocation at runtime: for this you can (for example) use the macro alloc(nBytes)+free:

mov edi,alloc(Param1) ; allocate memory (size=Param1)

; set bytes to low order byte of Param1
movzx eax,BYTE ptr Param2
xor ecx,ecx
.while ecx < Param1
    mov BYTE ptr [edi+ecx],al
    lea ecx,[ecx+1]
.endw

... do what ever

free edi ; free allocated memory
FPU in a trice: SmplMath
It's that simple!