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

Using assembler in C source

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



Joined: 18 Jul 2005
Posts: 9
Location: Hertfordshire. UK

View user's profile Send private message

Using assembler in C source
PostPosted: Fri Aug 11, 2006 3:17 am     Reply with quote

Can anyone suggest how I can alter the following assembler snippet so CCS compiler will like it, please?

Code:

incf   sRxTx_Pntr,F   // step the pointer
incf   sRxTx_Count,F   // step num chrs rcvd
movf   sRxTx_Pntr,W   // is pointer too far?
sublw   LOW sRx_BuffLimit   // check against limit address
btfsc   STATUS,0      // skip if greater (no ETX)


sRx_BuffLimit is defined as the address of the last byte in the sRxTx_Buffer which is Bank 2. The compiler doesn't like the use of LOW to get the lower byte of the address, which is all that is required here. So far my attempts to use C expressions to coerce it have failed.

I would like to avoid rewriting the code as it would, I think, get longert and this is a time critical interrupt handler.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 11:47 am     Reply with quote

Write a test program and look at the .LST file. What is it doing ?
It's only an 8-bit machine. What byte is it likely to be using ?
The answer in in the .LST file.
unitrant



Joined: 18 Jul 2005
Posts: 9
Location: Hertfordshire. UK

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 12:18 pm     Reply with quote

Thank you for your suggestion. The problem is that the compiler does not like any of my attempts to derive what is effectively an offset (8bit) from the base address of sRxTx_Buffer. Hence the code will not compile and no .lst file ensues.

I realise that the compiler has poor support for assembler code, not unreasonably, but I wanted to save converting this section of a reasonably sized assembler project until later. Probably easier to do it now after all.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 12:27 pm     Reply with quote

Look at the .LST file shown below for this test program:
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

#byte STATUS = 0x03

//======================================
void main()
{
int8  sRxTx_Pntr;
int8  sRxTx_Count;
int16 sRx_BuffLimit;

#asm
incf   sRxTx_Pntr,F    // step the pointer
incf   sRxTx_Count,F   // step num chrs rcvd
movf   sRxTx_Pntr,W    // is pointer too far?
sublw   sRx_BuffLimit  // check against limit address
btfsc   STATUS,0       // skip if greater (no ETX)
#endasm


while(1);
}


Code:
0000            00304 ... int8  sRxTx_Pntr;
0000            00305 ... int8  sRxTx_Count;
0000            00306 ... int16 sRx_BuffLimit;
0000            00307 ... 
0000            00308 ... #asm
0000            00309 ... incf   sRxTx_Pntr,F   
000C 1283       00310 BCF    03.5
000D 0AA1       00311 INCF   21,F
0000            00312 ... incf   sRxTx_Count,F   
000E 0AA2       00313 INCF   22,F
0000            00314 ... movf   sRxTx_Pntr,W 
000F 0821       00315 MOVF   21,W
0000            00316 ... sublw   sRx_BuffLimit 
0010 3C23       00317 SUBLW  23
0000            00318 ... btfsc   STATUS,0       
0011 1803       00319 BTFSC  03.0
0000            00320 ... #endasm

Symbols
main.sRxTx_Pntr                   00000021
main.sRxTx_Count                  00000022
main.sRx_BuffLimit                00000023
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Using assembler in C source
PostPosted: Fri Aug 11, 2006 12:49 pm     Reply with quote

unitrant wrote:

Code:

incf   sRxTx_Pntr,F   // step the pointer

It's 8-bit. You cant increment a 16-bit pointer in a single instruction.
unitrant wrote:

Code:

sublw   LOW sRx_BuffLimit   // check against limit address


You don't have to specify the low byte because the instruction only operates on a single byte.
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