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
  • "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!)

Reply
  • "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!)

Children
  • 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

  • " i just want to make sure that i got everything right."

    No: you need to put the delay routine in a separate 'C' file - all on its own.

    It is only the delay function that you want in assembler - you are currently converting main() as well!

  • ; 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
    Yes - insert your assembler code there!

    Note that the value of the 'duration' parameter is being passed in R7...

    "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
    No!

    You haven't inserted your assembler code where you said, have you?

    Remember that the value of the 'duration' parameter was passed in R7...

    Also, as mentioned elsewhere, don't convert 'main()' to assembler!

  • Thanks! This is the 'updated' .A51 code from .src
    I included my ASM code in it, and this time i didn't include the main. Is this correct?


    ; .\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?_delay?TESTMODE  SEGMENT CODE
    ?DT?_delay?TESTMODE  SEGMENT DATA OVERLAYABLE
    	PUBLIC	_delay
    
    	RSEG  ?DT?_delay?TESTMODE
    ?_delay?BYTE:
       duration?040:   DS   1
    ; #include <reg52.h>
    ;
    ; void delay( unsigned char duration )
    
    	RSEG  ?PR?_delay?TESTMODE
    _delay:
    
    	MOV  	duration?040,R7
    ;my assembly starts here
    PWM	EQU P0.1
    MRUN	EQU P0.4
    MDIR	EQU P0.3
    MRST	EQU P0.2
    MUP	EQU P0.0
    
    
    	ORG	0000H
    
    
    MAIN:	MOV 	P0, #0FFH
    	SETB	MRST
    	SETB 	MUP
    	SETB	MDIR
    
    
    	;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			 since it brought in to R7 so i replace it here?
    	DJNZ	R7,LOOP
    	CLR	MRUN
    	JMP	$
    
    
    DELAY: MOV 	R4,#3
    
    DEL: 	MOV 	R2,#00FFH
    	DJNZ 	R2,$
    	DJNZ 	R4,DEL
    
    	RET
    ; END OF _delay
    
    	END
    

  • "this time i didn't include the main."

    I think you must've posted the wrong code - it looks exactly the same as before.

    Remember, the only thing you need to do in assembler is the delay function; there should be no ORG, no fiddling with Ports, no CALL to the delay function - just the delay loop itself.

    Remember, the only reason you're doing this in assembler is so that you can know for sure exactly what machine instructions will be executed and, thus, exactly how long each iteration of the loop will take.
    You don't need to worry about this for the rest of your program, so you can just write that in straight 'C'

  • sorry.. So is this correct?

    ; .\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?_delay?TESTMODE  SEGMENT CODE
    ?DT?_delay?TESTMODE  SEGMENT DATA OVERLAYABLE
    	PUBLIC	_delay
    
    	RSEG  ?DT?_delay?TESTMODE
    ?_delay?BYTE:
       duration?040:   DS   1
    ; #include <reg52.h>
    ;
    ; void delay( unsigned char duration )
    
    	RSEG  ?PR?_delay?TESTMODE
    _delay:
    
    	MOV  	duration?040,R7
    
    DELAY: 	MOV 	R4,#3     ;start of my delay code
    
    DEL: 	MOV 	R2,#00FFH
    	DJNZ 	R2,$
    	DJNZ 	R4,DEL
    	DJNZ	R7, DELAY	; is this how u bring in the duration value that was passed in R7?
    	RET
    ; END OF _delay
    
    	END