×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

Check for Stack clash with Heap

Submitted by Steve Fewell

Routine: checkstackclash
Name: Check for Stack clash with Heap
Starting Address: &BD1E
Entry criteria: A = The BASIC Stack Pointer Low Byte, after the required number of bytes of storage space has been subtracted. C (Carry flag) = 0 if overflow occurred during the subtraction of the required number of bytes.

Description:
Store A back to the Stack Pointer Low Byte. Decrement &05 (The Stack Pointer High Byte), if necessary.

If the Stack Pointer High Byte is now less than the Heap high byte then there is no room in memory, so error (as the Stack is stored above the Heap).

If the Stack Pointer High Byte is equal to the Heap high Byte, then test the low bytes. If the Stack Pointer Low Byte is less than the Heap Low Byte then a "No Room" error is produced, otherwise the routine returns successfully.

Disassembly for the Check for Stack clash with Heap routine

BD1E   133 004 85 04 STA &04
BD20   176 002 B0 02 BCS 2 --> &BD24
BD22   198 005 C6 05 DEC &05
BD24   164 005 A4 05 LDY &05
BD26   196 003 C4 03 CPY &03
BD28   144 010 90 0A BCC 10 --> &BD34
BD2A   208 004 D0 04 BNE 4 --> &BD30
BD2C   197 002 C5 02 CMP &02
BD2E   144 004 90 04 BCC 4 --> &BD34
BD30 ` 096 60 RTS
...   ... ...
BD34 L 076 161 144 4C A1 90 JMP &90A1   Error: No Room

 


 Back to 8BS
Or