This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Assemble function templale callable in C51

Hi All
Here is my template to create quickly a function in assemlbe and call in C51
Enjoy

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Template of a function writen in assembly then call by C51 compiler
; Created by Huynh Vinh Ha - Vietnam, date 11/09/2004
; declare fname in C51: extern unsigned char fname(unsigned char x,char y)
; replace fname with actual name of your function
; replace MAIN with actual name of main program which call you function
; Input 1st parameter put in R7, 2nd in R5, 3rd R3 ( R7/R6 for int var)
; Return value
;bit : carry flag
;char R7
;int R6.R7
;long R4..R6
;float R4..R6
;pointer R1..R3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

?PR?_fname?MAIN SEGMENT CODE ; code location
?DT?_fname?MAIN SEGMENT DATA OVERLAYABLE ; data segment

PUBLIC _fname ; public name

RSEG ?DT?_fname?MAIN
?_fname?BYTE: ; declare local variables used in this function
x?040: DS 1 ; byte type variable
z?041: DS 1 ; byte
clk bit 90H.0 ; bit type var

RSEG ?PR?_fname?MAIN
_fname: ; begin function
USING 0
; MOV x?040,R7 ; get parameter to local variable x
;
; ------ do something
; -------
; ACALL DELAY ; call internal subroutine if present

; MOV R7,return_value ;
RET

; internal subroutine inside, for example
;DELAY: NOP
; RET

END ; END OF _fname

Parents
  • A far better approach is just to create a "dummy" 'C' function with the required return type, parameters, etc, and then compile it using the SRC directive.
    That way, you're guaranteed to get the correct result!


    Andy,

    isn't it sad that we have to post this every week?

    Erik

Reply
  • A far better approach is just to create a "dummy" 'C' function with the required return type, parameters, etc, and then compile it using the SRC directive.
    That way, you're guaranteed to get the correct result!


    Andy,

    isn't it sad that we have to post this every week?

    Erik

Children