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

C & Assembly

Can any one tell me how to mix C and Assembly in kiel in a single file?

Thanks in advance

Parents
  • Okay... here's something that seems to work. Simply put this code into a .S file and add it to your project.

             AREA |.text|, CODE, READONLY
             ARM
    PIOA_SODR EQU 0xFFFFF430 ; set output data register
    PIOA_CODR EQU 0xFFFFF434 ; clr output data register
    IOPIN_PA8 EQU 0x1<<8     ; I/O pin PA8 (1 << 8)
             ALIGN
    myfunc  FUNCTION
            EXPORT  myfunc
            MOV R1,#IOPIN_PA8
            LDR R0,=PIOA_SODR
            STR R1,[R0,#0]
            LDR R0,=PIOA_CODR
            STR R1,[R0,#0]
            BX LR
            ENDFUNC
            END
    

    Then add the below line to the C file you want to call 'myfunc' from,

    extern void myfunc(void);
    


    and then just call

    myfunc();
    


    from your C file. Works for me. Of course, there might be more to it, but this seems to have been enough for me to create a function in a RealView compatible ASM file that just toggles an I/O pin that I can then call from a C file in a RealView project. Dave :-)

Reply
  • Okay... here's something that seems to work. Simply put this code into a .S file and add it to your project.

             AREA |.text|, CODE, READONLY
             ARM
    PIOA_SODR EQU 0xFFFFF430 ; set output data register
    PIOA_CODR EQU 0xFFFFF434 ; clr output data register
    IOPIN_PA8 EQU 0x1<<8     ; I/O pin PA8 (1 << 8)
             ALIGN
    myfunc  FUNCTION
            EXPORT  myfunc
            MOV R1,#IOPIN_PA8
            LDR R0,=PIOA_SODR
            STR R1,[R0,#0]
            LDR R0,=PIOA_CODR
            STR R1,[R0,#0]
            BX LR
            ENDFUNC
            END
    

    Then add the below line to the C file you want to call 'myfunc' from,

    extern void myfunc(void);
    


    and then just call

    myfunc();
    


    from your C file. Works for me. Of course, there might be more to it, but this seems to have been enough for me to create a function in a RealView compatible ASM file that just toggles an I/O pin that I can then call from a C file in a RealView project. Dave :-)

Children
No data