mixing c with assembly

Status
Not open for further replies.

akub3

Newbie level 3
Joined
Mar 26, 2004
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
46
mixing c and assembly pic

Hi, I am currently implementing some algorithms on a pic microcontroller. I'm using the PIC18f452. i am however having problems calling c functions from the assembly code. The following is a section of my code:

auto char recvd_coord; // recvd coordinates
auto char current_coord; // current coordinates

extern unsigned char perform_xaveraging(auto char a,auto char b);

void main(void) {
auto char p;
p = perform_xaveraging (recvd_coord,current_coord);

}

/* functions to perform averaging calculation */

extern unsigned char perform_xaverageing (auto char a,auto char b) {
near auto char z;

if (current_coord>POSITIVE_XERR_RANGE || current_coord<NEGATIVE_XERR_RANGE ){
(a + b)/2 ;
z = ((a + b)/2);
return z;
}
else {
(a + b)/2 ;
z =((a + b)/2);
return z;
}
}

any ideas will be greatly appreciated,
akub3
 

I never used a PIC but...

Mixing assembly and higher level language requires the programmer be aware of how the high level language builds the stack for a call and treats the return values.

Some versions of C promote char to unsigned integer function calls, but this may be a 16bit microprocessor thing.

on other machines, some versions of C require or assume certain registers point to certain data structures (a line number counter for runtime errors, for instance) , if you are entering a C program anywhere but through the main( void ) function you have to be aware of this
 

Make a C program with call to perform_xaveraging. Force C compiler to generate assembler output and check how arguments (auto char a,auto char b) are placed on stack (or some other way). Now make the same in assembler.

Tom
 

Hi Guys, thanx for the suggestions. it works well now
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…