Example: main() int func(int x, int y) { { int a, b; .... .... func(a, b); .... } } Assembler code: main: xxxxx -> func: xxxxx xxxxx / xxxxx / xxxxx / xxxxx / BSR func - xxxxx
Because the "BSR func" will make the CPU jump to the first instruction in the function "func", you must pass the parameters (if any) to the function "func" BEFORE the "BSR func" instruction
Example: main() int func(int x, int y) { { int a, b; .... .... func(a, b); .... } }
main() int func(int x, int y) { { int a, b, c; return (x*x + y*y); int i, j, k; } c = func(a, b); k = func(i, j); } func() has 2 parameters and 1 return value Agreement: parameter 1 in register D0 parameter 2 in register D1 return value in register D7 The asembler program will look like this: main: MOVE.L a, D0 (pass a through D0) MOVE.L b, D1 (pass b through D1) BSR func ----------------------------+ | MOVE.L D7, c | | | MOVE.L i, D0 (pass i through D0) | MOVE.L j, D1 (pass j through D1) | BSR func -------------------------+ | | | MOVE.L D7, k V V func: (func(x,y)) MULS D0, D0 (Use the input parameters MULS D1, D1 put in the agreed locations) ADD.L D1, D0 ** D0 = x^2 + y^2 MOVE.L D0, D7 (put return value in previously agreed location) RTS
How to run the program:
|
|