,ll 6.6
,cs 10
,pl 66
,lm 0.2,0.5
,pn 1
,ju
,hd
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,,
,ft

,ce 1
9C-##
,,
,ce
OmegaSoft 6809 Cross Pascal Language Handbook (V1.0)
,ce
APPENDIX

APPENDIX C - RUNTIME ENVIRONMENT

SECTION OVERVIEW

In this implementation a minimum of 1 section and a maximum of 3 sections are used. The minimum section is of course the code section. Data section is automatically used if you have any string constants used with the append procdure, or if you define variables in data section, or have structured constants. Varib section is used if you define variables in varib section. Below is the organization of a program that uses all 3 sections, plus the room for the heap and stack.

        ROM or RAM                           RAM only

| CODE/RUNTIME |  DATA  |    | HEAP->         <-STACK |  VARIB  |

             
Runtime routines and data variables are referenced off of the program counter. Global variables and variables declared in varib section are referenced off of the Y register. If only constant values are kept in data section, then the code/runtime and data section can be kept in ROM or used on a system that write protects that area of memory or requires re-entrancy. Varib section starts 16 bytes above the global stack mark (a5) and so therefor there must be the command : v.start 10    in your linker command list. This is required even if you have no varib section variables since part of the global stack frame actually occupies those 16 bytes.

    We now present the heap/data stack areas graphically :
 
                     high
                     |      global stack frame     |
 global stack mark high-16
                     |      global stack frame     | 
                     high-26
                     |      global variables       |
data stack pointer 
                     | data stack grows down for   |
                     | local variables and expr.   |
                     | evaluation. Heap grows up   |
                     | for dynamic variable alloc. |
      heap pointer low
,pg
,ce
RUNTIME ENVIRONMENT
 
    global stack frame :

  |  R$KEY   | pointer to keyboard descriptor (if declared)
  <- +14
  |  R$AUX   | pointer to auxout descriptor (if declared)
  <- +12
  |  R$OUT   | pointer to output descriptor (if declared)
  <- +10
  |  R$IN    | pointer to input descriptor (if declared)
  <- +8
  |  R$PARM  | pointer to start of string for CLINE function
  <- +6 
  |  R$RANG  | flag for range function/variable
  <- +5 
  |  R$CONV  | flag for conversion function
  <- +4 
  |  R$HPPT  | heap pointer
  <- +2 
  |  R$HPLM  | heap limit
  <- +0 from global stack mark
  |          | not used 
  <- -2 
  |  R$SLIM  | system stack limit
  <- -4 
  |  R$GLOB  | global stack mark address
  <- -6 
  |  R$EFLG  | error mask
  <- -7 
  |  R$LSP   | spare
  <- -8 
  |  R$RDWR  | read/write descriptor address
  <- -10

    Procedure/Function stacking :
 
  
  |         parameters        |
  
  |    function return temp   |
  <- local stack mark
  |     local stack frame     |
  <- -10 from local stack mark
  | local variables and expr. |
  | evaluation.               |
  

    local stack frame :
 
  <- -0 from local stack mark
  |  R$SLNK  | static link
  <- -2 
  |  R$DLNK  | dynamic link
  <- -4 
  |  R$GLOB  | global stack mark address
  <- -6 
  |  R$EFLG  | error mask
  <- -7 
  |  R$LSP   | spare
  <- -8 
  |  R$RDWR  | read/write descriptor address
  <- -10 
,ce
RUNTIME ENVIRONMENT
  
    format of error mask
 
bits   7       .....       3      2        1        0
   
    |        not    used      | R$ECON | R$EIOE | R$ERNG |
    
 
    Range errors (4-12) disabled if R$ERNG zero
    I/O errors (17,18) disabled if R$EI0E zero
    Conversion errors (13-16) disabled if R$ECON zero (R$CONV is
    updated regardless of the state of R$ECON)
 
The static link is the address of the stack mark of the level enclosing this one (lexical) so that variables can be accessed properly at other levels. The dynamic link is the address of the stack mark of the caller. This is restored as the stack mark when this called procedure/function returns.

The CPU registers are used as follows during runtime :
 
   PC - program counter - program execution address
    S - system stack pointer
    U - data stack pointer
    Y - stack mark (base register)
    X - general purpose address and data register
    D - general purpose data register
