Rotate Right

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

User avatar
Jan Lichtenbelt
Posts: 790
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 122 times
Been thanked: 259 times
Contact:

Rotate Right

Postby Jan Lichtenbelt » Sat Dec 29, 2012 11:48 am

Hi All,

I met the flowing declaration problem of variables in a rotation right. Let make the problem more clear:

1) take 2 variables A and B, which are declared as 1 byte variable each. Say A=0x01 and B=0x10.
2) I want to place bit 0 of A into bit 7 of B (and all other bits in B shifted to right)
3) The most easy way is in the assembler code like:
Asm
{
RRF A,F // which places bit 0 of A into the carry bit
RRF B,F // which places the carry bit into bit 7 of B
}


So far so good. But now in Flowcode 5:
4) The variable A and B will become gbl_FCV_A and gbl_FCV_A in the assembler code. But
asm
{
RRF gbl_FCV_A,F
RRF glb_FCV_B,F
}

gives an error that these variabales are unknown
5) The variable A and B will become FCV_A and FCV_A in the C-code. But
asm
{
RRF FCV_A,F
RRF FCV_B,F
}

give also the error that these variables are unknown.

In principle 4) is the right assembler code and should be used as such. But it is interpreted as a C-code with wrong variable names.

My question:
Is there and easy/simple solution?

Kind regards

Jan Lichtenbelt

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Rotate Right

Postby Enamul » Sat Dec 29, 2012 1:02 pm

asm
{
RRF gbl_FCV_A,F
RRF glb_FCV_B,F
}
this is not right according to Boostc manual

It should be following which compiles fine..

Code: Select all

asm
{
RRF _FCV_A,F
RRF _FCV_B,F
}

To refer to a C variable from inline assembly, simply prefix its name with an
underscore '_'.
// Example showing use of bit tests and labels in inline assembly
#include <system.h>
void foo()
{
unsigned char i, b;
i = 0;
b = 12;
asm
{
start:
btfsc _i, 4
goto end
btfss _b, 0
goto iter
iter:
movlw 0
movwf _b
end:
}
}
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Jan Lichtenbelt
Posts: 790
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 122 times
Been thanked: 259 times
Contact:

Re: Rotate Right

Postby Jan Lichtenbelt » Sat Dec 29, 2012 4:03 pm

Dear Enamul,

Thanks a lot. It works!


Jan Lichtenbelt