News:

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

Macro Problem

Started by Infro_X, October 24, 2005, 05:11:00 PM

Previous topic - Next topic

Infro_X

I'm tring to figure out if this/ how this can be done.
Simply put, if the element size < the size of a pointer, add [pArrayEl],sizeof pointer, else add [pArrayEl],sizeof Element
EDIT: And I do know that I can put another condition jump, but %ElemSize is always going to be a define, and I want to use more of this type structured programming (maybe I should switch to C? lol)

#define GenericLinkedListArrayRunner(%pArrayEl,%ElemSize,%BlockSize) = \
mov eax,(%pArrayEl) \;mov eax, a pointer to some place in the macrokey
and eax,0-(%ElemSize) \;round eax down to the nearest macrokey size
jz >.E1 \;if (eax == 0) return 0;
and (%pArrayEl),0-(%BlockSize) \; ;round the pointer down to the size of the macro key array
\ ;MORE IF CODE FOR NEXT ADD, IF ElemSize <PTR, compare pArrayEl+4,eax jnb >.abovepointer, mov eax,pArrayEl, add eax,pointersize, retn 4
add eax,(%ElemSize) \;go to next macro key by adding the size of a macro key to the pointer
add (%pArrayEl),(%BlockSize) \; ;make the pointer point outside the size of the array, (eg. ARRAY[MACRO_KEY_ARRAY_SIZE])
cmp eax,(%pArrayEl) \;compare the current macro key to the end of the array, if the current is below the end, return
jae >.S1 \;else
.E1 \;
retn 4 \;
.S1 \;
and eax,0-(%BlockSize) \;round down to macro key array size. SHOULD NOT BE NESSISARY! but just in case.
sub eax,(%BlockSize) \;subtract to get to the correct macro key array
mov eax,[eax] \;the first element is a pointer the next linked list; Get the pointer
or eax,eax \;If no more arrays in linked list, return 0
jz <.E1 \;0
#IF ((%ElemSize)< PTRSIZE ) \
add eax,PTRSIZE \;skip over linked list and get first macrokey.
#ELSE \
add eax,(%ElemSize) \
#ENDIF \
jmp <.E1 ;return pointer to first element in next linked list.