next up previous contents index
Next: 3.14 int (16 bit) Up: 3.13 Interfacing with Assembler Previous: 3.13.2 Assembler Routine (non-reentrant)   Contents   Index

3.13.3 Assembler Routine (reentrant)

In this case the second parameter onwards will be passed on the stack, the parameters are pushed from right to left i.e. after the call the leftmost parameter will be on the top of the stack. Here is an example:

extern int asm_func(unsigned char, unsigned char); 
 
int c_func (unsigned char i, unsigned char j) reentrant  
{  
    return asm_func(i,j);  
}  
 
int main()  
{  
    return c_func(10,9);  
}
The corresponding assembler routine is:

.globl _asm_func  
_asm_func:  
    push _bp  
    mov _bp,sp  
    mov r2,dpl 
    mov a,_bp  
    add a,#0xfd  
    mov r0,a  
    add a,#0xfc ;? 
    mov r1,a  
    mov a,@r0  
    add a,r2 ;? 
    mov dpl,a  
    mov dph,#0x00  
    mov sp,_bp  
    pop _bp  
    ret
The compiling and linking procedure remains the same, however note the extra entry & exit linkage required for the assembler code, _bp is the stack frame pointer and is used to compute the offset into the stack for parameters and local variables.


next up previous contents index
Next: 3.14 int (16 bit) Up: 3.13 Interfacing with Assembler Previous: 3.13.2 Assembler Routine (non-reentrant)   Contents   Index
2008-10-02