GETARRAYSIZE PROTO :DWORD
_______________________________________________________

invoke GETARRAYSIZE, sizeof setgame_array
_________________________________________________

GETARRAYSIZE proc USES ebx sizeArray:DWORD
xor edx,edx
mov eax,sizeArray
mov ebx,4
div ebx
mov N,eax
sub N,1
xor eax,eax
ret 0
GETARRAYSIZE endp



This routine as well my program compile fine. The window is launched and GETARRAYSIZE is called to get the size of setgame_array to get the info to display my bitmaps. Then when i call it again with this:


invoke GETARRAYSIZE, sizeof play_array ;different array

the program crashes with a page fault

N is a global but it shouldn't matter since no other part of the program uses it at the same time.
Should i be returning the N value in eax instead. I really am stumped with this one.

Any help appreciated.
:rolleyes:
Posted on 2001-09-20 19:54:06 by titan
Are you sure it's this PROC that's crashing your proggie?
Why are you doing 'ret 0' - MASM will set that for you - try 'ret'.

Nothing to do with the crash, but...
sar eax,2 ;is very much like div 4!

Shouldn't it be called 'SETARRAYSIZE'?

If it's always constant, then:

SETARRAYSIZE MACRO asize:REQ
mov N,((asize) / 4) - 1
ENDM

SETARRAYSIZE sizeof play_array

Forgive me if I'm no help at all. :)
Posted on 2001-09-20 20:53:45 by bitRAKE
bitRAKE i understand what your saying and yes i forgive you because it was no help at all.

I did try "ret" instead of ret 0 with no luck
Same crash

The N is used in other procedures but not at the same time.
N is the value i want to obtain from GETARRAYSIZE
I just want to convert the array size in bytes to the actual number of elements.

Maybe your right...maybe something else i missed is crashing the prog.
Posted on 2001-09-20 21:03:58 by titan
It would be pretty dumb to call it 'SETARRAYSIZE' :)

The macro should work for you?
GETARRAYSIZE MACRO asize:REQ

mov N,((sizeof asize) / 4) - 1
ENDM

GETARRAYSIZE play_array
Your PROC looks functional.
Posted on 2001-09-20 21:08:59 by bitRAKE
i'll try that
probably tomorrow since i am now indulging in libation and may screw things up worse

thanx
:alright:
Posted on 2001-09-20 21:17:06 by titan
Just a minor typo

;xor ecx,ecx (in another part of the prog)

That little colon should not have been there

Anyways bitRAKE i tried to use your last macro but i got some errors to do with syntax. Can't understand why it wont work because it appears to do the same job as my procedure.
Posted on 2001-09-21 10:14:03 by titan
Just tried the macro:
play_array STRUCT

dd ?
dd ?
dd ?
play_array ENDS
.data
N dd 0
.code

GETARRAYSIZE MACRO asize:REQ
mov N,((sizeof asize) / 4) - 1
ENDM

GETARRAYSIZE play_array
No problem here? It generates code for 'mov N,2'.
Posted on 2001-09-21 17:32:57 by bitRAKE