I have a macro that I use with CBLOCK, which I find extremely helpful in allocating the use of the extremely limited RAM in the PIC processors. ---------- The macro: ---------- UpdateRam macro banktoupdate, lastused RAMBASE#v(banktoupdate) set lastused+1 updateramtemp set RAMTOP#v(banktoupdate)-RAMBASE#v(banktoupdate) MESSG Ram bank #v(banktoupdate) after lastused: next = #v(RAMBASE#v(banktoupdate)), left = #v(updateramtemp) endm ;UpdateRam ----------------------------------------- A few variables to be used by that macro: Note: these are for 16F876, change to suit processor being used... ----------------------------------------- RAMBASE0 set 0x20 RAMBASE1 set 0xa0 RAMBASE2 set 0x110 RAMBASE3 set 0x190 RAMTOP0 set 0x70 RAMTOP1 set 0xe0 RAMTOP2 set 0x170 RAMTOP3 set 0x1f0 ------------------------------------------------------------ A sample of using the macro to "declare" some RAM variables: ------------------------------------------------------------ ;Most ISR variables are in bank 0 cblock RAMBASE0 ;Start letting assembler allocate bank 0 starting here ISR_S_TMP ISR_PC_TMP ISR_FSR_TMP endc UpdateRam 0,ISR_FSR_TMP ---------------------------------------------------------------------------- --- When this is assembled, you get the following message in your assembler output: ---------------------------------------------------------------------------- --- Message[301] C:\CODE\TIMKEN\MEMORY.INC 51 : MESSAGE: (Ram bank 0 after ISR_FSR_TMP: next = 35, left = 77) ---------------------------------------------------------------------------- ---------------------------- Somewhere near the end of your program, you can put this to automatically check for overflowing the RAM: ---------------------------------------------------------------------------- ---------------------------- If ( RAMBASE0 > RAMTOP0) Error "Overflowed Bank 0 Register File" EndIf If ( RAMBASE1 > RAMTOP1) Error "Overflowed Bank 1 Register File" EndIf If ( RAMBASE2 > RAMTOP2) Error "Overflowed Bank 0 Register File" EndIf If ( RAMBASE3 > RAMTOP3) Error "Overflowed Bank 1 Register File" EndIf ---------------------------------------------------------------------------- ----------------------- I find that this helps make the primitive programming tools act somewhat more like something civilized, so that I can concentrate on the (still pretty painful) job of writing assembly code for a machine that combines in one processor all the worst memory-management schemes known to programmers. Now, mind you I like PIC's a lot for their price/performance, their peripherals, and Microchip's company philosophy, but I am getting pretty tired of programming them, and wish they could plop a nicer CPU onto those chips. > -----Original Message----- > From: Bob Ammerman [mailto:RAMMERMAN@PRODIGY.NET] > Sent: Tuesday, May 29, 2001 6:29 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]:EQU and CBLOCK > > > > CBLOCK 0x021 > > temp > > temp1 > > . > > . > > . > > ;(and so on) > > zzzzzzzz ;just a marker reg. > > ENDC > > > > IF zzzzzzzz >= 0X070 > > MESSG "BANK 0 IS FULL!!" > > ENDIF > > > > Quentin > > The test above should be: > > If zzzzzzzz > 0x70 > > It is ok for zzzzzzzz to be == 0x70. > > Bob Ammerman > RAm Systems > (contract development of high performance, high function, low-level > software) > > -- > http://www.piclist.com hint: The PICList is archived three different > ways. See http://www.piclist.com/#archives for details. > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.