Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 6th February 2009, 07:27 AM   #1
Default Referencing C variables in In-line assembly

Hi,

I'm wrote a small 18F in-line assembly snippet in MPLAB referencing a local C variable. From the results I'm not referencing the C variable correctly.

Any ideas?

unsigned char count = 0;
unsigned char current_count = 10;

count = current_count;

_asm

// Loop until count is 0
start:
DECFSZ count, 1, 0
BRA start
GOTO done
done:

_endasm
zevious is offline  
Old 6th February 2009, 08:32 AM   #2
Default

To use a variable without managing the banking you need to have it in access ram. Try moving your variable so it is global and put it in the access area by doing,
Code:
#pragma udata access somename
near unsigned char count;
#pragma udata
Mike.
Pommie is online now  
Old 6th February 2009, 03:03 PM   #3
Default

Thanks Mike,

How would I manage the banking to avoid allocating it in access ram?
zevious is offline  
Old 6th February 2009, 03:11 PM   #4
Default

Well, if you run out of access ram you need to load the bsr with the bank number of your variable. What is wrong with using the access ram, the compiler doesn't seem to!!

Mike.
Pommie is online now  
Old 6th February 2009, 09:20 PM   #5
Default

Thanks again Mike,

I believe I can use access RAM (near), and it do sound like it would end up being faster and require less cycles. But lets say I wanted to set the BSR with bank information to access the count variable in my simple loop example above. How would I accomplish that?

I am sorry for these newbie questions but I'm just starting up with MPASM syntax (as you can tell)
zevious is offline  
Old 7th February 2009, 02:54 AM   #6
Default

You would simply do movlb count.

Mike.
Pommie is online now  
Reply

Tags
18f, assembly, in-line, mplab, pic

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Assembly Variables for PICs! Peter_wadley Micro Controllers 9 22nd June 2007 06:05 AM
How reliable is cross referencing parts? Canti General Electronics Chat 23 3rd May 2007 10:30 PM
in-line assembly for PicBasic Compiler Erwin_Macaraig Micro Controllers 0 3rd November 2004 08:02 AM
ground referencing a differential input signal giaracam Electronic Projects Design/Ideas/Reviews 2 22nd September 2004 01:41 PM
Where is variables located in a PIC? egh01 Micro Controllers 0 22nd November 2003 01:08 PM



All times are GMT. The time now is 12:03 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker