1STACK(5)                      File Formats Manual                     STACK(5)
2
3
4

NAME

6       stack -  2.10BSD PDP-11 C stack frame conventions
7

DESCRIPTION

9       The standard C stack frame layout:
10
11              ------------------
12              |...nth argument |              push arguments in reverse order
13              ------------------
14              |second argument |
15              ------------------
16              | first argument |
17              ------------------              JSR PC,*$_FOO
18              | return address |
19              ------------------              JSR R5,CSV
20              |  old R5 value  | <-----
21              ------------------      |
22              |previous overlay|      |
23              |     number     |      |
24              ------------------      |
25              |       r4       |      |
26              ------------------      |
27              |       r3       |      |
28              ------------------      |
29              |       r2       |      |
30              ------------------      |
31              | first local var|      | This is the top of the stack
32              ------------------      | when the called routine ``starts''
33              |     routine    |      |
34              |    allocates   |      |
35              |     storage    |      |       SUB $n,SP
36              |    temporary   |      |
37              ------------------      |
38              | push arguments |      |
39              | of next routine|      |
40              ------------------      |       JSR PC,*$_BAR
41              | return address |      |
42              ------------------      |       JSR R5,CSV
43              | old R5 value---+-------
44              ------------------      ^
45              |previous overlay|      |
46              |     number     |      |
47              ------------------      |
48              | r4/43/r2/...   |      |
49              ------------------
50              | and so on..... |
51
52
53       The  stack  pushes  downward through memory addresses.  Overlay numbers
54       saved in non-overlaid objects are always zero, but  the  simplification
55       of  not  having to maintain two different stack frame formats more than
56       outweighs the extra few micro seconds (less  than  four)  necessary  to
57       save the zero ...
58
59       Functions  returning integers leave their return value in R0; functions
60       returning floating constants use FR0; functions returning  longs  leave
61       return  values  in  R1/R0  (R0  high word, R1 low); functions returning
62       structures leave a pointer to bss storage (one chunk of which is  allo‐
63       cated  for each such routine) in R0, and the caller will copy from that
64       bss storage to the local destination.
65
66       Local variables are allocated in such a way that they are  referred  to
67       as ``-N(R5)'', arguments are referred to as ``+N(R5)''; arguments start
68       at 4(R5), the first integer local declared will be at -10(R5).
69
70       The SP normally points at the first word available for parameter  push‐
71       ing.   A  function taking only single word as a parameter can be called
72       simply by moving the parameter into  (SP)  and  calling  the  function,
73       without  having  to  clean  the parameter off the stack on return.  Any
74       parameters passed after the  first  (actually  "Nth")  must  be  pushed
75       before  the  call  and  cleaned off afterwards.  If the function has no
76       local variables and calls no functions, it will allocate no  stack  and
77       the word labelled ``first local var'' will be unused.
78
79       It is important to note that routines know how many arguments they pass
80       to a function, and will adjust the stack accordingly after  a  function
81       returns.
82

NOTE

84       This stack frame format is the same as that used by overlaid objects in
85       2.9BSD.
86

AUTHOR

88       John F. Woods, MIT Concouse Computer Center
89
90
91
923rd Berkeley Distribution                                             STACK(5)
Impressum