accessing registers in asm

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
raghavmonga
Posts: 14
Joined: Thu Apr 17, 2008 10:10 am
Contact:

accessing registers in asm

Post by raghavmonga »

i am having some difficulty in accessing the general purpose registers of pic for assembly level coding .

i am getting the error: error in built in assembly

do we need to access the registers through their RAM address or do we need the define the variables in flowcode or something else?
i have tried the former two but to no avail.


program in which external variable is used:
bsf _status,5 ;Go to bank 1
movlw 00h ;Put 00000 into W
movwf _trisb ;Move 00000 onto TRISA - all pins set to output
bcf _status,5 ;Come back to Bank 0
movlw AAh
movwf _FCV_A
addlw _FCV_A ,0
movwf _portb

program in which register address is used
bsf _status,5 ;Go to bank 1
movlw 00h ;Put 00000 into W
movwf _trisb ;Move 00000 onto TRISA - all pins set to output
bcf _status,5 ;Come back to Bank 0
movlw AAh
movwf 25h
addlw 25h,0
movwf _portb

both didn't work
plz help.
i am using Flowcode V3 for PIC

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: accessing registers in asm

Post by Benj »

Hello

After compiling your code I was given a line number that indicated the problem was with the following line of code.

Code: Select all

addlw _FCV_A ,0
Changing the code to the following fixed the problem

Code: Select all

addwf _FCV_A ,0
So the completed code is now.

Code: Select all

asm{
bsf _status,5 ;Go to bank 1
movlw 00h ;Put 00000 into W
movwf _trisb ;Move 00000 onto TRISA - all pins set to output
bcf _status,5 ;Come back to Bank 0
movlw AAh
movwf _FCV_A
addwf _FCV_A ,0
movwf _portb
}

raghavmonga
Posts: 14
Joined: Thu Apr 17, 2008 10:10 am
Contact:

Re: accessing registers in asm

Post by raghavmonga »

Thanks Ben, that worked fine.
But i am still not able to access the registers using their respective addresses in the RAM.
please help

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: accessing registers in asm

Post by Benj »

Hello

You must use the register name. BoostC does not seem to support the direct register addresses.

raghavmonga
Posts: 14
Joined: Thu Apr 17, 2008 10:10 am
Contact:

Re: accessing registers in asm

Post by raghavmonga »

but the general purpose registers in PIC don't have any name. they have to be used by using their addresses in RAM.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: accessing registers in asm

Post by Benj »

Hello

Can you not use a variable instead then the compiler can assign the register dynamically.

Post Reply