+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Full Member level 5
    Points: 4,284, Level: 15

    Join Date
    Nov 2005
    Posts
    292
    Helped
    12 / 12
    Points
    4,284
    Level
    15

    How to mix C & assembly

    Hello friends,


    presently i am working on microcontrollers and I am using Keil compiler to progrm.
    I want to know how to mix embedded c and assembly in a single program
    plz help me.

    Thank you.
    john

    •   AltAdvertisement

        
       

  2. #2
    Member level 1
    Points: 1,466, Level: 8

    Join Date
    Sep 2005
    Posts
    40
    Helped
    4 / 4
    Points
    1,466
    Level
    8

    Re: How to mix C & assembly

    hi
    when u r writing a c function that hasto be used in assembly again declare that c function as global in c program and in asm declare it as extern and call it similiarly u can do for asm program also (declaring fun as global abd acessing it as extern).



  3. #3
    Full Member level 2
    Points: 1,845, Level: 9

    Join Date
    Jul 2005
    Location
    Canada
    Posts
    139
    Helped
    6 / 6
    Points
    1,845
    Level
    9

    Re: How to mix C & assembly

    When you want to use assembly in a C program, you have to use a pragma directive.

    Code:
    extern void test ();
    
    void main (void)  {
      test ();
    
    #pragma asm
      JMP   $  ; endless loop
    #pragma endasm
    }
    It is called inline assembly, if you want to search for it in the user manuals.

    Hope it helps,

    cyberblak



    •   AltAdvertisement

        
       

  4. #4
    Full Member level 5
    Points: 4,284, Level: 15

    Join Date
    Nov 2005
    Posts
    292
    Helped
    12 / 12
    Points
    4,284
    Level
    15

    Re: How to mix C & assembly

    hi cyberblak


    can i know more about pragma?where can i find more information about it?which user manual are you talking about?if you have that manual,could you share for me here?any links or websites you now,related to this?how do i know when to mix assembly in C program or not?when should i go for this mixing?what will be the effect on the code?can you clarify me?

    regards
    john



  5. #5
    Member level 1
    Points: 2,233, Level: 10

    Join Date
    Dec 2002
    Posts
    32
    Helped
    3 / 3
    Points
    2,233
    Level
    10

    Re: How to mix C & assembly

    I am not an expert, but mixing C and ASM code is described in C51.PDF, Chapter 6 Segment Naming Conventions (p.159) and next, especially Interfacing C Programs to Assembler (p.163). This file is inside keil_home\C51\HLP directory.
    Hope it helps.



  6. #6
    Full Member level 5
    Points: 4,284, Level: 15

    Join Date
    Nov 2005
    Posts
    292
    Helped
    12 / 12
    Points
    4,284
    Level
    15

    Re: How to mix C & assembly

    hi jan noha


    thanks for your siggestion,i shall check out the C51.PDF,chapter 6.

    regards
    john



    •   AltAdvertisement

        
       

  7. #7
    Advanced Member level 3
    Points: 6,852, Level: 19
    SphinX's Avatar
    Join Date
    Jan 2002
    Location
    EGYPT
    Posts
    822
    Helped
    59 / 59
    Points
    6,852
    Level
    19

    How to mix C & assembly

    Salam,

    Read Chapter 5 ( page 88 )

    "Final Word on 8051"

    http://paginas.fe.up.pt/~ee99043/8051/files/8051.zip

    Thanks



  8. #8
    Full Member level 5
    Points: 4,284, Level: 15

    Join Date
    Nov 2005
    Posts
    292
    Helped
    12 / 12
    Points
    4,284
    Level
    15

    Re: How to mix C & assembly

    hi sphinx

    thanks for the link,i think its good tutorial.i found a good book which has information about C and assembly.its Fundamentals of Embedded Sodftware by Lewis,u can download the book from internet,by search through google,its easily available.the book tells about Where C and Asssembly meets,also this book is very good for RTOS concepts.

    regards
    john

    Added after 1 hours 58 minutes:

    MODERATOR ACTION: interesting to see you answering your own questions??
    hi all,


    Usually, embedded C compilers include a keyword such as "asm". The
    syntax varies between compilers (because it's not a standard).
    Sometimes it's spelt "assem" or "#pragma assembler" or something like
    that. However, "asm" is most typical. The statements will be
    something along the line of:

    asm "nop";

    or

    asm { nop; mov a,b; }

    or something vaguely like that.

    Hope this helps.



    regards
    john



--[[ ]]--