??? 08/06/06 10:35 Read: times |
#121722 - calling c function from assembly |
hello friends,
i want to use c function in my assembly program,after reading keil c51 user i came to know about calling conventions used to interface c and assembly but i am unable to do it properly due to some doubts can please clearify it to me. i have assembled following c file to src #pragma SRC #pragma SMALL #pragma NOREGPARMS int function(int v_a, char v_b, bit v_c,long v_d,bit v_e) { v_d=v_a+v_b; } below is the src file ; .\CSAMPLE1.SRC generated from: .\CSAMPLE1.C NAME CSAMPLE1 ?PR?function?CSAMPLE1 SEGMENT CODE ?DT?function?CSAMPLE1 SEGMENT DATA OVERLAYABLE ?BI?function?CSAMPLE1 SEGMENT BIT OVERLAYABLE PUBLIC ?function?BIT PUBLIC ?function?BYTE PUBLIC function RSEG ?DT?function?CSAMPLE1 ?function?BYTE: v_a?040: DS 2 v_b?041: DS 1 v_d?043: DS 4 RSEG ?BI?function?CSAMPLE1 ?function?BIT: v_c?042: DBIT 1 v_e?044: DBIT 1 ; /*------------------------------------------------------------------------------ ; CSAMPLE1.C ; ; Copyright 1995-1999 Keil Software, Inc. ; ------------------------------------------------------------------------------*/ ; ; ; #pragma SRC ; #pragma SMALL ; #pragma NOREGPARMS ; //unsigned int asmfunc1(unsigned int arg); ; int function(int v_a, char v_b, bit v_c,long v_d,bit v_e) RSEG ?PR?function?CSAMPLE1 USING 0 function: ; SOURCE LINE # 12 ; { ; SOURCE LINE # 13 ; v_d=v_a+v_b; ; SOURCE LINE # 14 MOV R7,v_b?041 MOV A,R7 RLC A SUBB A,ACC MOV R6,A MOV A,v_a?040+01H ADD A,R7 MOV R7,A MOV A,v_a?040 ADDC A,R6 MOV R6,A RLC A SUBB A,ACC MOV v_d?043+03H,R7 MOV v_d?043+02H,R6 MOV v_d?043+01H,A MOV v_d?043,A ; } ; SOURCE LINE # 15 RET ; END OF function END please tell me the meaning of following assembler output in above code MOV R7,v_b?041 MOV v_d?043+03H,R7 MOV v_d?043+02H,R6 MOV v_d?043+01H,A MOV v_d?043,A what are these numbers 40,41,43? folowing is the code used to call function "function" from assembly but it gives error of undefined varibales EXTRN CODE (function) EXTRN DATA (?function?BYTE) EXTRN BIT (?function?BIT) MOV R6,#HIGH intval MOV R7,#LOW intval MOV R7,#charconst SETB ?function?BIT+0 MOV ?function?BYTE+3,longval+0 MOV ?function?BYTE+4,longval+1 MOV ?function?BYTE+5,longval+2 MOV ?function?BYTE+6,longval+3 MOV C,bitvalue MOV ?function?BIT+1,C LCALL function MOV intresult+0,R6 MOV intresult+1,R7 thanks kuldeep |
Topic | Author | Date |
calling c function from assembly | 01/01/70 00:00 | |
More reading required | 01/01/70 00:00 | |
AsmCallC | 01/01/70 00:00 | |
Absolute addresses?? | 01/01/70 00:00 | |
legacy | 01/01/70 00:00 | |
not really | 01/01/70 00:00 | |
NOREGPARAMS | 01/01/70 00:00 | |
Keil example | 01/01/70 00:00 | |
undefined varibales | 01/01/70 00:00 | |
Wouldnt it be easier... | 01/01/70 00:00 | |
Eh??? | 01/01/70 00:00 | |
inline | 01/01/70 00:00 | |
what I do and recommend![]() | 01/01/70 00:00 |