C code/asm

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

User avatar
psf
Posts: 41
Joined: Mon Jun 25, 2007 9:44 pm
Location: Italia
Has thanked: 5 times
Been thanked: 2 times
Contact:

C code/asm

Postby psf » Sun Jul 01, 2007 10:21 am

I have to add a macro in asm code.
I follow the help file hints (_FCV etc) but it still give "missing semicolon...error)
They are only 30 line of simple asm, i wont translate in C (i dont' know) and neither in flowchart because Flowcode will build 100 line code for this!!!(so the timing will KO)
This is an example (not real) of what I need:

label1
btfsc portb,7
goto label1
call macro1
bcf status,C
rrf var2,F
return

macro1
nop
decfsz var1
goto macro1
return

Can you write for me the code that I need to insert in this C BLOCK?

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

Postby Benj » Mon Jul 02, 2007 10:29 am

Hello

Here is your code. I have reorganised it a little but i think the main problem was this line.

Code: Select all

decfsz _FCV_VAR1


which needed to be changed to

Code: Select all

decfsz _FCV_VAR1, F


Here is a complete listing of your code which should compile without any errors.

Code: Select all

asm{
label1:
btfsc _portb,7
goto label1
mac1:
nop
decfsz _FCV_VAR1,F
goto mac1
bcf _status,C
rrf _FCV_VAR2,F
return
}

User avatar
psf
Posts: 41
Joined: Mon Jun 25, 2007 9:44 pm
Location: Italia
Has thanked: 5 times
Been thanked: 2 times
Contact:

Postby psf » Mon Jul 02, 2007 6:29 pm

Thanks for your reply, but I invented the code for learn the right method... if I had to call a macro in my asm code I just
CALL MACRO1 I suppose. In the first time I used _label 1 for label and call _ macro 1 for macro.... OK I'll try. thanks.

User avatar
Steve
Matrix Staff
Posts: 3110
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 396 times
Contact:

Postby Steve » Tue Jul 10, 2007 10:04 am

If you are using "CALL" in assembly, then the subroutine you are calling should be declared within the "supplementary code" window of Flowcode.

For example, if you had your own assembly subroutine like this:

Code: Select all

BIT_DELAY:
MOVLW 0x18
MOVWF _FCV_DELAY_COUNT
BIT_WAIT:
NOP
DECFSZ _FCV_DELAY_COUNT, F
GOTO BIT_WAIT


Then you would need to create a 'C' function in the Supplementary Code's "implementations" window like this:

Code: Select all

void bit_delay()
{
    asm
    {
        MOVLW 0x18
        MOVWF _FCV_DELAY_COUNT
        BIT_WAIT:
        NOP
        DECFSZ _FCV_DELAY_COUNT, F
        GOTO BIT_WAIT
    }
}


In fact, you do not need to declare a Flowcode "DELAY_COUNT" variable. It would be better to use a local 'C' variable like this:

Code: Select all

void bit_delay()
{
    char cDelayCount;
    asm
    {
        MOVLW 0x18
        MOVWF _cDelayCount
        BIT_WAIT:
        NOP
        DECFSZ _cDelayCount, F
        GOTO BIT_WAIT
    }
}


Then, anytime you want to call this routine, use a 'C' icon with either a straight 'C' function call:

Code: Select all

bit_delay();


Or from within your own embedded assembly:

Code: Select all

asm
{
  .
  .
  .
  CALL bit_delay
  .
  .
  .
}

keesp
Posts: 17
Joined: Wed Sep 22, 2010 11:53 am
Contact:

Re: C code/asm

Postby keesp » Mon Jan 31, 2011 9:09 pm

Hi Steve,

In Flowcode 4, what is the correct way to make a subroutine call in a asm block?

I am trying to get the program below to run, but it keeps telling me it doesn't understand 'routine' after the Call.

Kind regards,

Kees

asm
{
BSF _status, RP0 ;
MOVLW 0x0 ;
MOVWF _trisa ;
BCF _status, RP0 ;
CALL Routine ;
GOTO Labelend ;

Routine:
MOVLW 0x03 ;
MOVWF _porta ;
RETURN ;

Labelend:
}

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

Re: C code/asm

Postby Benj » Tue Feb 01, 2011 10:08 am

Hello Kees,

Why not use C code its so much easier to read and use.

trisa = 0x0;
porta = 0x03;

There is a manual on the BoostC compiler available from the "Flowcode v4\BoostC\" directory named boostc.pdf. This should detail what the assembler code is capable of.

keesp
Posts: 17
Joined: Wed Sep 22, 2010 11:53 am
Contact:

Re: C code/asm

Postby keesp » Tue Feb 01, 2011 1:41 pm

Hi Ben,

I am aware of this, but because the assignment is part of a course that aims to teach assembly, we want to show how subroutine calls are made. If, however, it is quite complicated in boostc, then maybe I'll skip this altogether ~)

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

Re: C code/asm

Postby Benj » Tue Feb 01, 2011 2:34 pm

Hello,

Here is a forum topic from the sourceboost forum detailing assembler macros in BoostC.
http://www.sourceboost.ipbhost.com/lofi ... t2032.html

Looks like assembler macros/subroutines are not supported by the compiler.

However I then came across this topic which seems to suggest they are supported.
http://forum.sourceboost.com/index.php? ... entry12625

Here is the code. You can give it a go but looking again the forum does not mention BoostC so this could be using their assembler compiler.

Code: Select all

main
call ONIRLED
goto main

ONIRLED
bsf STATUS,RP0
movlw 0x00
movwf TRISA
bcf STATUS,RP0
movlw 0xff
movwf PORTA
call delay
movlw 0x00
movwf PORTA
call delay
return

keesp
Posts: 17
Joined: Wed Sep 22, 2010 11:53 am
Contact:

Re: C code/asm

Postby keesp » Thu Feb 03, 2011 9:59 am

It seems that I'll have to accept my losses on this one! Thanks Benj for searching. The example you found has probably been compiled with C2C or similar. BoostC only allows the C-style option.

Kees

jeannoor
Posts: 5
Joined: Wed May 23, 2012 10:36 am
Contact:

Re: C code/asm

Postby jeannoor » Wed May 23, 2012 12:08 pm

hello everyone
i try to insert the bit delay(); function in a flowcode programme but it didn't work i don't know
this is my programme
if any one can help
Attachments
asm in.fcf
asm & C code on flowcode programme
(5.5 KiB) Downloaded 307 times

jeannoor
Posts: 5
Joined: Wed May 23, 2012 10:36 am
Contact:

Re: C code/asm

Postby jeannoor » Wed May 23, 2012 1:35 pm

this is the err :

Code: Select all

C:\Documents and Settings\Administrateur\Bureau\Nouveau dossier\asm in.c(118): error: general error
C:\Documents and Settings\Administrateur\Bureau\Nouveau dossier\asm in.c(138): error: general error
asm in.c failure

failure

Return code = 1