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 CCS Technical Support

Accessing hi byte of int16 in assembly

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



Joined: 09 Oct 2008
Posts: 4
Location: Long Island, NY

View user's profile Send private message

Accessing hi byte of int16 in assembly
PostPosted: Mon Oct 20, 2008 8:36 am     Reply with quote

I read through the forum and found a way to do this by using the '&' prefix: http://www.ccsinfo.com/forum/viewtopic.php?t=7220

Code:
   bcf     TMR1ON
   movf    Next_Time, W
   addwf   TMR1, F
   btfsc   C
   incf    TMR1H, F
   movf    &Next_Time+1, W


Next_Time is located at 0x28 according to the .lst file:
Code:
Next_Time                         00000028


But it doesn't access 0x29 in the second movf!?!
Code:
                00484 ....................    bcf     TMR1ON
0015 1010       00485 BCF    10.0
                00486 ....................    movf    Next_Time, W
0016 0828       00487 MOVF   28,W
                00488 ....................    addwf   TMR1, F
0017 078E       00489 ADDWF  0E,F
                00490 ....................    btfsc   C
0018 1803       00491 BTFSC  03.0
                00492 ....................    incf    TMR1H, F
0019 0A8F       00493 INCF   0F,F
                00494 ....................    movf    &Next_Time+1, W
001A 082A       00495 MOVF   2A,W


Adding parenthesis or dropping the "+1" doesn't work. Next_Time is declared as an int16.

My compiler is Ver 4.080. uP is rfPIC12F675 (12F675 w/RF transmitter).

Ideas?

Thanks.

Tom
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Accessing hi byte of int16 in assembly
PostPosted: Mon Oct 20, 2008 8:59 am     Reply with quote

Try this:
Code:

#byte Next_Time_H=Next_Time+1
  . . .
   movf  Next_Time_H,W


This has the advantage of also working outside of the assembly language block as in:

Code:

   int  k;
  k = Next_Time_H;

_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
embedded_tom



Joined: 09 Oct 2008
Posts: 4
Location: Long Island, NY

View user's profile Send private message

Re: Accessing hi byte of int16 in assembly
PostPosted: Tue Oct 21, 2008 7:26 am     Reply with quote

Thanks, but got this error for the #byte statement: Error 43 Expecting a declaration.

tom
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Accessing hi byte of int16 in assembly
PostPosted: Tue Oct 21, 2008 7:30 am     Reply with quote

embedded_tom wrote:
Thanks, but got this error for the #byte statement: Error 43 Expecting a declaration.

tom

Please post the code showing how you used the #byte directive. It is a valid CCS directive. Look it up in the CCS help file.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
embedded_tom



Joined: 09 Oct 2008
Posts: 4
Location: Long Island, NY

View user's profile Send private message

PostPosted: Tue Oct 21, 2008 7:34 am     Reply with quote

I did review #byte in the CCS manual. Here's what I used:
Code:
#byte Next_TimeH = Next_Time + 1;

Is #byte similar to "assign" in other compilers?

I just tried this & it worked:
Code:
   movf    make8(Next_Time,1), W


Thanks for the push in the right direction!

tom
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Tue Oct 21, 2008 9:20 am     Reply with quote

embedded_tom wrote:
I did review #byte in the CCS manual. Here's what I used:
Code:
#byte Next_TimeH = Next_Time + 1;


The problem is the ';' at the end. Take it off and it should work.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
embedded_tom



Joined: 09 Oct 2008
Posts: 4
Location: Long Island, NY

View user's profile Send private message

PostPosted: Tue Oct 21, 2008 2:30 pm     Reply with quote

Yep, that did it.

Thanks.

tom
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