A.7.2 Function Interface

The number of arguments should be carefully selected so that all arguments can be set in registers (up to four). If there are too many arguments, turn them into a structure and pass the pointer. If the structure itself is passed through and forth, instead of the pointer of the structure, the structure may be too large to be set in a register. When arguments are set in registers, calling and processing at the entry and exit of the function can be simplified. In addition, space in the stack area can be saved. Note that registers R1 to R4 are to be used for arguments.

[Example]

Function f has four more arguments than the number of registers for arguments.

Source code before improvement

void call_func()
{
    func(1,2,3,4,5,6,7,8);
}

 

Assembly-language expansion code before improvement

_call_func:
     SUB #04H,R0
     MOV.L #08070605H,[R0]
     MOV.L #00000004H,R4
     MOV.L #00000003H,R3
     MOV.L #00000002H,R2
     MOV.L #00000001H,R1
     BSR _func
     ADD #04H,R0
     RTS

 

Source code after improvement

struct str{
     char a;
     char b;
     char c;
     char d;
     char e;
     char f;
     char g;
     char h;
};
struct str arg = {1,2,3,4,5,6,7,8};
 
void call_func()
{
     func(&arg);
}

 

Assembly-language expansion code after improvement

_call_func:
     MOV.L #arg,R1
     BRA _func