PIC If...then....else directive

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Please can someone help.
I'm quite new to PIC directives and I am having loads of trouble with the
following "simple" code.

ADRESH holds the value of 2D

IF ADRESH > 0x2D
            GOTO LOOP
ELSE
            GOTO LOOP1
ENDIF

The problem is that the if statement tests the address of ADRESH and not the
value of ADRESH.

How do I test the value held in the register?

Many thanks.




Re: PIC If...then....else directive
Quoted text here. Click to load it

If this is assembly language (which it looks to be), then you have the wrong
idea about these directives. They are for conditional assembly. They are
equivalent to this in C:

#if adresh > 0x2d
   compile this
#else
   compile this
#endif

The directives don't generate code to read registers and decide which way to
go.


Re: PIC If...then....else directive
->IF ADRESH > 0x2D
->            GOTO LOOP
->ELSE
->            GOTO LOOP1
->ENDIF
->
-
-If this is assembly language (which it looks to be), then you have the wrong
-idea about these directives. They are for conditional assembly. They are
-equivalent to this in C:
-
-#if adresh > 0x2d
-   compile this
-#else
-   compile this
-#endif
-
-The directives don't generate code to read registers and decide which way to
-go.

Correct. BTW the C directives work in PIC assembly so the code you listed
will compile fine.

The code you need, and the theory behind it, can be found here:

http://www.piclist.com/techref/microchip/compcon.htm

BAJ

Re: PIC If...then....else directive
Quoted text here. Click to load it


As Gary correctly pointed out, the code you posted implements
"conditional assembly".  I.E. the code is parsed and acted upon only at
assembly time (never at run time).  And, of course, at assembly time
your register, ADRESH, exists only as an *address*; since the location
doesn't actually exist at assembly time, its contents cannot be tested
then.

Re: PIC If...then....else directive
Quoted text here. Click to load it
Is there perhaps a way to achieve the intended result using some form
of macro?


Re: PIC If...then....else directive
Quoted text here. Click to load it


What is a macro?  It's just a set of one or more instructions that the
assembler inserts into your code.  And those instructions get executed
only at run time.  No, I think a macro won't do what you want.

But I'm beginning to suspect that I don't understand what you want to
do.

Maybe you want to define a CONSTANT and then, depending on that value,
have either
GOTO LOOP
or
GOTO LOOP1
assembled into your code??

Re: PIC If...then....else directive
Quoted text here. Click to load it

Please don't confuse me with the original poster.

I'm sure we all wrote a lot of code that looks something like
(obviously depending on instruction set)

CJNE    A, #255, l1; if A10% then
MOV    B, #1
JMP    l2
l1: ; else
MOV    B, #2
l2: ; endif

my question was is there some kind of efficient way to macro-ize this
so as not to bother with two labels, as well as make the code more
readable.

    

Re: PIC If...then....else directive
Quoted text here. Click to load it

It really would depend on the macro capabilities of the assembler. The problem
is automatically generating the labels needed. You could have the macro use
some assembler symbol (an EQU) and have your macro increment the symbol when
called. One problem is that some assemblers only allow a symbol to be defined
once, so:
XX EQU 1

XX EQU XX + 1

will cause an error. If your assembler takes it, then you still have the
problem of creating the symbol.

Ideally, you'd want to concatenate the symbol with a string:

LABEL+XX

I don't know how many assemblers are this sophisticated. I seem to recall that
the old PDP-11 MACRO-11 assembler could do this.

Of course, one could always write a separate macro processor then feed its
output to the assembler.



Re: PIC If...then....else directive
:
: my question was is there some kind of efficient way to macro-ize this
: so as not to bother with two labels, as well as make the code more
: readable.
:
:

Take a look at the 'structured assembly' stuff on this page:
http://picbook.com/downloads.html (get SASM2002.09.28). You'll also need
MP_SASM if you don't have MPLAB installed.

An example of using it:
IF_    .z.
    MOVLF    250,ALIVECNT
    bcf PORTA,RA4
ENDIF_

This generate runtime code that's what you are wanting.

ttyl,

--buddy            

--
Remove '.spaminator' and '.invalid' from email address
when replying.


Site Timeline