The routine is below, but I use the _maxram value from the device header. In most cases this would be OK, but on some devices you don't actually seem to have the amount of RAM this (and the datasheet) suggests. I'm using the 46K22 which has 3936 bytes, but the top 40 of these bytes are actually SFRs.
So, my main question, how do I find the 'top' RAM address reliably?
A secondary question this has highlighted, where I to write a program which uses all available RAM, does Swordfish know not to use these top 40 bytes, and if so, how? (Or have I misunderstood something here?)
Code: Select all
{
****************************************************************************
* Name : ClearRAM *
* Purpose : Clears all processor RAM *
****************************************************************************
}
Public Sub ClearRAM()
Dim
RAMAddress As FSR0, // address of RAM location to be cleared
RAMClear As POSTDEC0 // post decrementing pointer to RAM
Const TOPRAM = _maxram // Get the address of the top of memory
RAMAddress = TOPRAM // Set FSR to point to top of memory
Asm-
loop1
clrf postdec0 // Clear RAM location
tstfsz fsr0h // FSR0H 0?
bra loop1 // No, carry on clearing
loop2 // Yes, means we only have $FF to $00 to clear
clrf postdec0 // Clear RAM location
tstfsz fsr0l // FSR0L 0?
bra loop2 // No, carry on clearing
clrf postdec0 // Yes, clear last byte then we are done
End Asm
End Sub