We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
How can I create an assembly function? How can I call it from c? Thanx..
1) I like to use a text editor, and run the source file through the assembler. 2) Declare the name of the function PUBLIC with an underscore in front:
PUBLIC _MyFunc _MyFunc: RET
The simplest way to create a C-callable assembly file, is to start with an outline in 'C', then let the compiler turn it into assembly source by using the SRC directive - see the Manual. You can be certain that the compiler knows exactly how to name the function, pass parameters, allocate local variables, and return a value in a C-compatible way. Once you have created this assembly outline, throw the 'C' file away and just work on that file in assembler. Add the assembly file to your project, and uVision will automatically use the assembler to translate it
Thanx...
When I make something like this: 1).src file with the following code
PUBLIC _koko _koko: mov A,R7; mov B,R5; DIV AB; mov R7,B; RET end
#include <AT89X51.H> extern char koko(char c,char d); void main(void) { P0=koko(1,2); }
*** WARNING L5: CODE SPACE MEMORY OVERLAP FROM: 0000H TO: 0006H
How can this be resolved? by following the following suggestion TO THE LETTER The simplest way to create a C-callable assembly file, is to start with an outline in 'C', then let the compiler turn it into assembly source by using the SRC directive - see the Manual Erik
Assembly language has an "ORG" directive that tells the assembler where the instructions are located. It also lets you declare "segments" to put your code into so that the linker can relocate them. Without the benefit of these mechanisms, your code will go at address 0000h, where it conflicts with the restart vector. Take a look at some of the example assembly to see how this works. Or, as Erik suggests, use the SRC directive and have the compiler generate a sample file from C that actually does what you want.
"use the SRC directive and have the compiler generate a sample file from C that actually does what you want." As I said before, if you let the compiler do it, you can be certain that the compiler will generate code using all the correct conventions for 'C'-compatibility!