Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to mix C & assembly

Status
Not open for further replies.

john2020

Full Member level 5
Joined
Nov 13, 2005
Messages
292
Helped
12
Reputation
24
Reaction score
8
Trophy points
1,298
Activity points
4,911
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
 

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).
 

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
 

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
 

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.
 

hi jan noha


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

regards
john
 

Salam,

Read Chapter 5 ( page 88 )

"Final Word on 8051"

**broken link removed**

Thanks
 

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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top