|
|
void A(...) { .... B(...); .... } void C(...) { .... D(...); .... } void D(...) { .... A(...); .... } |
The call chain can be arbitrary deep !!!
|
main() { int a, b, c; c = sum(a, b); } |
int sum(int x, int y) { x = x + 1; y = y + 1; return (x*x + y*y); } |
main() { c = func_1(a, b); } |
int func(int x, int y) { int k, l, m; .... m = func(k, l); } |
|
The ds assembler directive can only create (= reserve space) for one copy of local variable !!!
main ---------> func1 -----------> func2 ----------> func3 Stack: +------------+ | ret. func2 | +------------+ +------------+ | ret. func1 | | ret. func1 | +------------+ +------------+ +------------+ | ret. main | | ret. main | | ret. main | +------------+ +------------+ +------------+ |
main ------------> func1 --------------> func2 -------------> func3 push func1 param push func2 param push fucn3 param bsr func1 bsr func2 bsr func3 Stack: +------------+ | ret. func2 | +------------+ | func3 param| +------------+ +------------+ | ret. func1 | | ret. func1 | +------------+ +------------+ | func2 param| | func2 param| +------------+ +------------+ +------------+ | ret. main | | ret. main | | ret. main | +------------+ +------------+ +------------+ | func1 param| | func1 param| | func1 param| +------------+ +------------+ +------------+ |
+-------------+ 4004 | | +-------------+ 4008 | | +-------------+ <---- a7 = 4012 4012 | aaaaaaaa | +-------------+ 4016 | bbbbbbbb | +-------------+ | ........ | (each rectangle represents 4 bytes) |
+-------------+ 4004 | | +-------------+ <---- a7 = 4008 4008 | 6789 | +-------------+ 4012 | aaaaaaaa | +-------------+ 4016 | bbbbbbbb | +-------------+ | ........ | (each rectangle represents 4 bytes) |
suba.l #4, a7 move.l #6789, (a7) |
move.l <ea>, -(a7) is same as: suba.l #4, a7 move.l <ea>, (a7) move.w <ea>, -(a7) is same as: suba.l #2, a7 move.w <ea>, (a7) |
(I.e., I try to break down this complex topic into a number of simpler topics --- hope this will help you understand the complex topic)
|
The 2nd method is the goal of this piece meal treatment of this complex topic:
|