Using the SRC Directive

You may use the C51 compiler to generate the shell for an assembly routine you want to write or to help determine the passing conventions your assembly routine should use. The SRC command-line directive specifies that C51 generate an assembly file instead of an object file. For example, the following C source file:
#pragma SRC
#pragma SMALL

unsigned int asmfunc1 (
unsigned int arg)
{
return (1 + arg);
}

will generate the following assembly output file when compiled using the SRC directive.

; ASM1.SRC generated from: ASM1.C


NAME ASM1

?PR?_asmfunc1?ASM1 SEGMENT CODE
PUBLIC _asmfunc1
; #pragma SRC
; #pragma SMALL
;
; unsigned int asmfunc1 (

RSEG ?PR?_asmfunc1?ASM1
USING 0
_asmfunc1:
;---- Variable 'arg?00' assigned to Register 'R6/R7' ----
; SOURCE LINE # 4
; unsigned int arg)
; {
; SOURCE LINE # 6
; return (1 + arg);
; SOURCE LINE # 7
MOV A,R7
ADD A,#01H
MOV R7,A
CLR A
ADDC A,R6
MOV R6,A
; }
; SOURCE LINE # 8
?C0001:
RET
; END OF _asmfunc1

END

In this example, note that the function name, asmfunc1, is prefixed with an underscore character signifying that arguments are passed in registers. The arg  parameter is passed using R6 and R7.

The following example shows the assembly source generated for the same function; however, register parameter passing has been disabled using the NOREGPARMS directive.

; ASM2.SRC generated from: ASM2.C


NAME ASM2

?PR?asmfunc1?ASM2 SEGMENT CODE
?DT?asmfunc1?ASM2 SEGMENT DATA
PUBLIC ?asmfunc1?BYTE
PUBLIC asmfunc1

RSEG ?DT?asmfunc1?ASM2
?asmfunc1?BYTE:
arg?00: DS 2
; #pragma SRC
; #pragma SMALL
; #pragma NOREGPARMS
;
; unsigned int asmfunc1 (

RSEG ?PR?asmfunc1?ASM2
USING 0
asmfunc1:
; SOURCE LINE # 5
; unsigned int arg)
; {
; SOURCE LINE # 7
; return (1 + arg);
; SOURCE LINE # 8
MOV A,arg?00+01H
ADD A,#01H
MOV R7,A
CLR A
ADDC A,arg?00
MOV R6,A
; }
; SOURCE LINE # 9
?C0001:
RET
; END OF asmfunc1

END

Note in this example that the function name, asmfunc1,  is not prefixed with an underscore character and that the arg  parameter is passed in the ?asmfunc1?BYTE  segment.