Multiple Entry Points Multiple entry points allow different function names, different parameter lists, default parameters, etc. Example int fn( int a = 1, int b = 2 ) { return( a + b ); }
Multiple Entry Points Multiple entry points allow different function names, different parameter lists, default parameters, etc. Example int fn( int a = 1, int b = 2 ) { return( a + b ); } can be written in assembly as .global %function fn_ab, fn_b, fn, sum push {lr} fn_ab: mov r0, #1 /* default first parameter */ fn_b: mov r1, #2 /* default second parameter */
Multiple Entry Points The previous example can be written in assembly as .text .global fn_ab, fn_b, fn, sum .type fn_ab, %function .type fn_b, %function .type fn, %function .type sum, %function fn_ab: mov r0, #1 /* default first parameter */ fn_b: mov r1, #2 /* default second parameter */ fn: sum: add r0, r0, r1 /* add parameters and return sum */ bx lr
Multiple Entry Points with fn() becoming call fn_ab fn(3) becoming call fn_b after the caller places 3 in r0 fn(4,6) becoming call fn (or call sum) after the caller places 4 in r0 and 6 in r1 so that a driver like this #include<stdio.h> int fn_ab(); int fn_b(int); int fn(int, int); int sum(int, int); int main() { printf("fn_ab() returns %d\n",fn_ab()); printf("fn_b(3) returns %d\n",fn_b(3)); printf("fn(4,6) returns %d\n",fn(4,6)); printf("sum(5,7) returns %d\n",sum(5,7)); return 0; }
Multiple Entry Points will print fn_ab() returns 3 fn_b(3) returns 5 fn(4,6) returns 10 sum(5,7) returns 12 Of course, multiple exit paths are also possible.