IPB

Welcome Guest ( Log In | Register )

> How To Get C Variable Address For Use In Asm{} ?, For a PIC18
MrZebra
post Jun 15 2007, 05:33 PM
Post #1


Newbrie


Group: Members
Posts: 2
Joined: 14-June 07
Member No.: 3,664



Hi - a n00b here...

I have a PIC18 device and I'd like to get the address of one of my C variables so I can use a pointer to it in inline assembly. I see in the manual that I can use "movlw _variable" to get the address in the W register, but to set the indirection registers I need 12 bits (8 for FSR0L, and 4 for FSR0H). "movlw _variable" just seems to me to get the lower 8 bits, how do I get the upper bits so I can set up the indirection registers properly?

I made a quick test in C and looked at the disassembly instructions and it does what I was expecting it to do... two separate mov instructions, one for the low byte of FSR and one for the high nybble. One thing I don't understand though, the code generated by the compiler as writing a number greater than 4 bits into FSR0H, even though FSR0H can only accept 4 bits. The compiler generated "MOVF 0x5a, W, ACCESS", "MOVWF 0xfea, ACCESS". The upper bits should be ignored, but why would the compiler generate this?

I did the same thing on a PIC16 and it worked because the FSR is only 8 bits not 12. Does the linker set the FSR0H register in the PIC18 the same way it sets the correct bank for a PIC16?

TIA,

--- MrZebra
update SourceBoost release 6.97 is available.
Download Now
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
emte
post Jun 18 2007, 03:21 AM
Post #2


Super Enthusiast
***

Group: EstablishedMember
Posts: 378
Joined: 8-December 06
From: Victoria, BC, Canada
Member No.: 2,230



Using a simple underscore with the c variable name gives you access to the variable in asm
for almost all compilers.

CODE
int x = 2;

asm MOVF _x,W


--------------------
Good intentions always exist, intelligent thought patterns ... not quite as much

Are you linked in?
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 3rd September 2010 - 02:49 PM