Hi!

I'm working with a PIC18F and desperately need to figure a way to determine the size of free RAM.

I went through the PBP documentation and it says PBP will allocate RAM in some "predetermined order": (from first to last)
LONG, WORD, BYTE, BIT, LONG_ARRAYS, WORD_ARRAYS, BIT_ARRAYS

So I tried declaring some variables at the very end of the program to hopefully be placed at the end and then a simple RAM_END - lastVar (in assembly) would give the free ram... BUT...
The variables are not allocated at all as described in the manual. Words, bytes, arrays (smaller one) are scattered all over the place...
I get the the "best" result declaring some "odd sized" byte array like lastVar var byte[19] which seems to be "at the end" (at least, at the moment). But is there any rule?? How can I be sure it will stay "at the end"?

I tried declaring arrays of various sizes (1, 2, 3, 4, 5..7, 19, 123, 500...) and for some reason the 19-entry array is put last, example code:

Code:
define OSC 64


var0 var byte[133] system
var1 var word
var2 var word
var3 var byte
var4 var byte
var5 var byte[5]
var6 var word[2]
var7 var bit[30]


vGLOB var byte[8] SYSTEM


aTemp1 var vGLOB[0]    
aTemp2 var vGLOB[1]    
aTemp3 var vGLOB[2]    
aTemp4 var vGLOB[4]    


bTemp1 var vGLOB[2]
bTemp2 var vGLOB[2] 
bTemp3 var vGLOB[3] 


bitval var bit


var8 var byte


ramUsed dw _last_ram0
ramFree dw RAM_END-_last_ram

;.....


END


_last_ram0 var byte[19]
_last_ram var byte[7]
_last_ram2 var byte[1]
_dum_b1 var byte
_last_ram3 var bit[8]
_dum_b2 var byte 
_last_ramX var byte[2]
_dum_b3 var byte
_last_ramW var word[2]
_dum_b4 var byte
_dum_b5 var bit

Anyone have some idea how to "surely" determine the first free location or remaining free RAM?

Thanks!

MCulibrk