CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PCW CCS: Return from assembly function ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
eng_amr
Guest







PCW CCS: Return from assembly function ?
PostPosted: Sun Jul 13, 2003 4:11 pm     Reply with quote

Hi,

I have a assembly function like that

void myfunc (void)
{

#asm
" // my assembly lines
"
return
"
"
return
#endasm

}

I want to know how can i return from the assembly function .
I tried the _return_ found it in the manual.
But it give me this error Undefined identifier _return_
And how can i return with a value in assembly function ?

Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515928
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: PCW CCS: Return from assembly function ?
PostPosted: Sun Jul 13, 2003 4:49 pm     Reply with quote

:=I want to know how can i return from the assembly function .
:=And how can i return with a value in assembly function ?
--------------------------------------------------------
How about this:

<PRE>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
<BR>
char test(char value);
<BR>
//======================================================
void main()
{
char c;
<BR>
c = test(0x20);
<BR>
while(1);
}
//=======================================================
<BR>
char test(char value)
{
#asm
movlw 0x08 // This is the return code for this test.
btfsc value, 0 // Is bit 0 of value set ?
goto done // If so, return 0x08
<BR>
movlw 0x40 // This is the return code for this test.
btfsc value, 1 // Is bit 1 of value set ?
goto done // If so, return 0x40
<BR>
// etc.
<BR>
movlw 0x00 // Default return value
done:
movwf _return_ // Put the return value into _return_
#endasm
<BR>
}
</PRE>

Note: The tests, and the return codes are completely arbitrary
and are just shown to demonstrate the idea.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515929
eng_amr
Guest







Re: PCW CCS: Return from assembly function ?
PostPosted: Mon Jul 14, 2003 5:38 am     Reply with quote

Hi,

Thanks your code works fine but when i try to compile my code it state that error "Undefined identifier _return_ "

here is my code

#include <16F84.h>
#Case

#fuses XT,NOWDT,NOPROTECT,PUT
#use delay (clock=4000000)
#byte portb=0x06
#byte porta=0x05

unsigned char Cntr,P_Val;

int Pulsin(void);


void main() {

int c;

// set_tris_b(0x00);
// set_tris_a(0xff);

c=Pulsin();


while(1);

}

int Pulsin(void)
{

// pulse measurement subroutine
#asm
Clrwdt // Walk the dog
Clrf Cntr // Clear the variables used,
Clrf P_Val // prior to the subroutine
Trans: Btfss porta,2 // Wait for a 1 to 0 transition
Goto Edge // Edge found!
Incfsz P_Val // Else, increment P-VAL until >255
Goto Trans
Incfsz Cntr // Loop until 255
Goto Trans
goto done
Edge: Clrf P_Val // A 1 to 0 transition occurred
Edge_LP: Btfsc porta,2 // Count how long it's logic 0
goto done
Clrwdt // Walk the dog
Nop // Timing loop
Nop
Nop
Nop
Nop
Incfsz P_Val // Increment P_VAL until >255
Goto Edge_LP
done:
movf P_Val,w
movwf _return_

#endasm
}






:=:=I want to know how can i return from the assembly function .
:=:=And how can i return with a value in assembly function ?
:=--------------------------------------------------------
:=How about this:
:=
:=<PRE>
:=#include "c:\Program Files\Picc\Devices\16F877.H"
:=#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
:=#use delay(clock = 8000000)
:=#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
:=<BR>
:=char test(char value);
:=<BR>
:=//======================================================
:=void main()
:={
:=char c;
:=<BR>
:=c = test(0x20);
:=<BR>
:=while(1);
:=}
:=//=======================================================
:=<BR>
:=char test(char value)
:={
:=#asm
:=movlw 0x08 // This is the return code for this test.
:=btfsc value, 0 // Is bit 0 of value set ?
:=goto done // If so, return 0x08
:=<BR>
:=movlw 0x40 // This is the return code for this test.
:=btfsc value, 1 // Is bit 1 of value set ?
:=goto done // If so, return 0x40
:=<BR>
:=// etc.
:=<BR>
:=movlw 0x00 // Default return value
:=done:
:=movwf _return_ // Put the return value into _return_
:=#endasm
:=<BR>
:=}
:=</PRE>
:=
:=Note: The tests, and the return codes are completely arbitrary
:=and are just shown to demonstrate the idea.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515942
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: PCW CCS: Return from assembly function ?
PostPosted: Mon Jul 14, 2003 12:07 pm     Reply with quote

<font face="Courier New" size=-1>:=
:=Thanks your code works fine but when i try to compile my code it state that error "Undefined identifier _return_ "
--------------------------------------------------------

The problem is caused by using the #case statement, while
typing _return_ with lower case letters.

If you compile with the +LS option, you can see the symbol
table at the end of the MPLAB .LST file. The symbol table
spells it as: _RETURN_

So if you use #case, you must use upper case, like this:

movwf _RETURN_</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515962
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group