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

error while inserting assembly in C

Hi, i got this this error while trying to add some assembly code to my C. How do i activate the src-control? Any help is appreciated. Thank you!


error C272: 'asm/endasm' requires src-control to be active

Parents
  • I think the section titled, "Interfacing C to Assembler" might have just a tiny bit to do with it...

    Hint: the easiest way is to just create a "skeleton" function in 'C', then get the compiler to convert that to assembler by using the SRC directive. You then throw away the original 'C' file, and fill-in your required code in the assembler file generated by the compiler.

Reply
  • I think the section titled, "Interfacing C to Assembler" might have just a tiny bit to do with it...

    Hint: the easiest way is to just create a "skeleton" function in 'C', then get the compiler to convert that to assembler by using the SRC directive. You then throw away the original 'C' file, and fill-in your required code in the assembler file generated by the compiler.

Children
  • Thanks i'll check on that. The hint that you gave are quite hard to understand. Is there any example code, that i can refer to? Thanks anyway.

  • The hint that you gave are quite hard to understand. Is there any example code, that i can refer to
    Easy, you male it yourself.

    Say that you want a delay routine which, as we all know, must be in asm to stay precise.

    1) make the routine in C in a separate module
    2) compile it
    3) throw that C file away
    4) use the .lst file generated as your template

    Erik

  • Thanks! so, i'm suppose to write any C code, as skeleton? as long as it generate a LST file? then i type in my code in the LST file. Then what? how do i call this LST file from my original C file? I hope i'm making myself clear.

  • I would consider that recipe unduly hard on the newbie. It's a good deal easier to get started with a C module that you compile to assembly directly, then copy the resulting file *.SRC to *.A51, and start working on that. Once you've got off the ground, remove the *.c and *.src files.

  • "Thanks! so, i'm suppose to write any C code, as skeleton? as long as it generate a LST file?"

    No - When Erik said "LST" he should've said "SRC"

    As it tells you in the Manual, when you compile a 'C' source file, file.c, using the SRC directive, the compiler output is an Assembler source file, file.src.
    You can then pass this Assembler source to the assembler, and it will assemble it to an object file, file.obj.

    So what you do is:

    1) make the skeleton routine in C in a separate file
    2) compile it using the SRC directive
    3) throw that C file away
    4) use the .SRC file generated as your template (rename it to .A51 if you like)

    You do this because you can be certain that the Compiler will generate a correct skeleton for a function to be called from 'C'

    And this is only for the purpose of generating an Assembler function to be called from 'C' - you don't do any of this for 'C' functions to be called from 'C'!

  • "It's a good deal easier to get started with a C module that you compile to assembly directly, then copy the resulting file *.SRC ..."

    Yes - I think Erik's just confusing his LST with his SRC?

  • actually not really "confusing" the two, more like forgetting that difference in the simplification. When I do it, I actually use a "cut" from the .lst pasted into the .a51 (I like the "comments"). This serves me very well, but for a newbie, of course, using .src is the better of the two.

    Erik

  • "Thanks! so, i'm suppose to write any C code, as skeleton?"

    No: not any 'C' code - this is purely for the case where you want to generate a skeleton for a 'C'-callable assembler function.

  • hmm.. sorry i'm getting confious. ok, here's my main objective. i wrote a delay in asm(desired asm). so in my original 'c' code, i would like to call this delay, when necessary. so, from what i understand : -

    1) Firstly, i create a 'skeleton' C code for my desired asm. but what do u exactly mean by that? what should i type in the 'skeleton' C code?

    2) let's say i finish step1, i'm suppose to edit the .src code generated. (replace the asm code inside with my desired asm) and save it as .a51

    3)delete the .c file and .src

    4) next step?

    again, i'm really appreciated with the help of everyone. Thanks

  • 4) next step?
    4) assemble and link in the /a51 module

    Erik

  • "1) Firstly, i create a 'skeleton' C code for my desired asm. but what do u exactly mean by that? what should i type in the 'skeleton' C code?"

    A "skeleton" 'C' delay function would look some thing like this:

    void delay( unsigned char duration )
    {
       // Nothing in the body - it's just a skeleton!
    }
    "2) let's say i finish step1, i'm suppose to edit the .src code generated. (replace the asm code inside with my desired asm) and save it as .a51"

    The .src file will contain the assembler skeleton corresponding to the above 'C' skeleton - you will see how the parameter is passed in, and it will have all the appropriate segment names, etc.

    All you do is insert the appropriate assembler delay code into the body of the function.

    "3)delete the .c file and .src

    4) next step?"


    Add the .a51 file to your Project.
    By default, uVision recognises .a51 as an assembler source file, so it will automatically use the assembler to translate it. (you might even find that it recognises .src as asembler source - so you wouldn't even need to rename it!)

  • So, this will be my 'skeleton' C code??

    #include <reg52.h>
    
    /* Function declarations */
    void delay( unsigned char duration );
    /* Program routines */
    void main (void)
    {
    
    }
    
    void delay( unsigned char duration )
    {
       // Nothing in the body - it's just a skeleton!
    }
    
    

    and with the above C, below is the .src code generated

    ; .\TestMode.SRC generated from: TestMode.C
    ; COMPILER INVOKED BY:
    ;        C:\Keil\C51\BIN\C51.EXE TestMode.C BROWSE DEBUG OBJECTEXTEND SRC(.\TestMode.SRC)
    
    $NOMOD51
    
    NAME	TESTMODE
    
    P0	DATA	080H
    P1	DATA	090H
    P2	DATA	0A0H
    P3	DATA	0B0H
    T0	BIT	0B0H.4
    AC	BIT	0D0H.6
    T1	BIT	0B0H.5
    T2	BIT	090H.0
    EA	BIT	0A8H.7
    IE	DATA	0A8H
    EXF2	BIT	0C8H.6
    RD	BIT	0B0H.7
    ES	BIT	0A8H.4
    IP	DATA	0B8H
    RI	BIT	098H.0
    INT0	BIT	0B0H.2
    CY	BIT	0D0H.7
    TI	BIT	098H.1
    INT1	BIT	0B0H.3
    RCAP2H	DATA	0CBH
    PS	BIT	0B8H.4
    SP	DATA	081H
    T2EX	BIT	090H.1
    OV	BIT	0D0H.2
    RCAP2L	DATA	0CAH
    C_T2	BIT	0C8H.1
    WR	BIT	0B0H.6
    RCLK	BIT	0C8H.5
    TCLK	BIT	0C8H.4
    SBUF	DATA	099H
    PCON	DATA	087H
    SCON	DATA	098H
    TMOD	DATA	089H
    TCON	DATA	088H
    IE0	BIT	088H.1
    IE1	BIT	088H.3
    B	DATA	0F0H
    CP_RL2	BIT	0C8H.0
    ACC	DATA	0E0H
    ET0	BIT	0A8H.1
    ET1	BIT	0A8H.3
    TF0	BIT	088H.5
    ET2	BIT	0A8H.5
    TF1	BIT	088H.7
    TF2	BIT	0C8H.7
    RB8	BIT	098H.2
    TH0	DATA	08CH
    EX0	BIT	0A8H.0
    IT0	BIT	088H.0
    TH1	DATA	08DH
    TB8	BIT	098H.3
    EX1	BIT	0A8H.2
    IT1	BIT	088H.2
    TH2	DATA	0CDH
    P	BIT	0D0H.0
    SM0	BIT	098H.7
    TL0	DATA	08AH
    SM1	BIT	098H.6
    TL1	DATA	08BH
    SM2	BIT	098H.5
    TL2	DATA	0CCH
    PT0	BIT	0B8H.1
    PT1	BIT	0B8H.3
    RS0	BIT	0D0H.3
    PT2	BIT	0B8H.5
    TR0	BIT	088H.4
    RS1	BIT	0D0H.4
    TR1	BIT	088H.6
    TR2	BIT	0C8H.2
    PX0	BIT	0B8H.0
    PX1	BIT	0B8H.2
    DPH	DATA	083H
    DPL	DATA	082H
    EXEN2	BIT	0C8H.3
    REN	BIT	098H.4
    T2CON	DATA	0C8H
    RXD	BIT	0B0H.0
    TXD	BIT	0B0H.1
    F0	BIT	0D0H.5
    PSW	DATA	0D0H
    ?PR?main?TESTMODE    SEGMENT CODE
    ?PR?_delay?TESTMODE  SEGMENT CODE
    ?DT?_delay?TESTMODE  SEGMENT DATA OVERLAYABLE
    	EXTRN	CODE (?C_STARTUP)
    	PUBLIC	_delay
    	PUBLIC	main
    
    	RSEG  ?DT?_delay?TESTMODE
    ?_delay?BYTE:
       duration?140:   DS   1
    ; #include <reg52.h>
    ;
    ;
    ; /* Function declarations */
    ; void delay( unsigned char duration );
    ;
    ; /* Program routines */
    ; void main (void)
    
    	RSEG  ?PR?main?TESTMODE
    main:
    			; SOURCE LINE # 8
    ; {
    			; SOURCE LINE # 9
    ;
    ; }
    			; SOURCE LINE # 11
    	RET
    ; END OF main
    
    ;
    ; void delay( unsigned char duration )
    
    	RSEG  ?PR?_delay?TESTMODE
    _delay:
    			; SOURCE LINE # 13
    	MOV  	duration?140,R7
    ; {
    			; SOURCE LINE # 14
    
    			;I'm suppose to insert my asm code here??
    
    ;    // Nothing in the body - it's just a skeleton!
    ; }
    			; SOURCE LINE # 16
    	RET
    ; END OF _delay
    
    	END
    
    

    and this will be my asm code

    PWM	EQU P0.1
    
    	ORG	0000H
    
    MAIN	MOV 	R3,#50			; this is the value that i want to change (the duration value in the skeleton C code)
    LOOP:	SETB 	PWM
    	CALL 	DELAY
    	CLR 	PWM
    	CALL	DELAY
    	DJNZ 	R3,LOOP
    
    	CLR	MRUN
    	JMP	$
    
    
    DELAY: MOV 	R4,#3
    
    DEL: 	MOV 	R2,#00FFH
    	DJNZ 	R2,$
    	DJNZ 	R4,DEL
    	RET
    
    	END
    
    

    Am I getting this right? Any advice? Thanks again for everyone's help, really appreciated.

  • Sorry for cut & paste my entire code here, i just want to make sure that i got everything right. Thanks