Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Referencing C variables in In-line assembly

Status
Not open for further replies.

zevious

New Member
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
 
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.
 
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.
 
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)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top