how to include asm code in .C file?????

Status
Not open for further replies.

Dhans

Junior Member level 3
Joined
Sep 14, 2005
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,473
include asm in c

hi to all
How to include some asm code in between .C file in 8051.?
can anyone help me?????
 

include asm code in c

I don't know the details of the compiler that you are using. However, in various C compiler it's as follows:
1. Declare a function/procedure/label in the asm file that have a global linkage property, i.e. something like:
Code:
.gobal my_function

my_function:
; your function asm routines

2. You can call this function from your C code with:
Code:
my_function();

3. Some notes:
a. I don't know the specifics of your compiler, so please read its documentations.
b. The linkers need the asm file to be compiled into object code to be able to be linked.
c. The ".global" keyword in the code in point 1 is only a hint. Your compiler might have different syntax

goodluck
 

asm code in c files

The compiler I use i.e. WinAvr allows something like

asm("asembly command");
e.g asm("nop");
 

include asm file in c

here are good links for interfacing C and ASM


**broken link removed**

**broken link removed**

**broken link removed**


**broken link removed**
 

include c code assembler

In many compilers, you will find something like this:

#pragma asm

............
............ Your ASM code here
............
#pragma endasm

This whole code snippet is inserted anywhere inside the C code.
 

c51 inline assembler keil example inc __asm

hi..

C macros provide a convenient way to insert extended inline assembly code into your C source code. Macros demand extra care because they expand in a single logical line. Follow these rules to create trouble-free macros:

Enclose the __asm block in braces ('{}').
Put the __asm keyword in front of each assembly instruction.
Use only traditional C comment delimiters ('/*') and ('*/'). Assembly-style comment delimiters (';') and single-line C comment delimiters ('//') are not possible.
For example:

#define ABLOCK __asm { /* comment */ \
__asm mov R5,#0x10 \
__asm l1: mov rl4,#'}' \
__asm mov R6,R5 \
__asm jnbs R6.2,l1 \
}

The __asm keywords (highlighted in red) seem superfluous. However, they are required because C macros are expanded in a single line.

The preprocessor's handling of '#' within macro definitions that begin with the __asm keyword is relaxed (since # is used for immediate values in assembly language). In standard C, an assembly immediate value like #0x10 would cause an error in the preprocessor phase because it violates the C preprocessor rules.

The following example demonstrates how to define and use an extended inline assembly block in a macro.

#define ABLOCK __asm { /* comment */ \
__asm mov R5,#0x10 \
__asm l1: mov rl4,#'}' \
__asm mov R6,R5 \
__asm bset R6.3 \
__asm jnbs R6.2,l1 \
}

int i;

void main (void) {
i = 1;
ABLOCK // expand inline assembly macro
i = 2;
}

if u r using keil compiler.

regards..
sujith
 

include assembly in a c file

hi..

if u r using keil...

right click on source group... check the generate src tab...

the code syntax is:

#pragma asm

stmts

#endasm

regards...
sujith

Added after 1 minutes:

sorry

#pragma endasm
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…