Lockedhelp using if statement in MPLAB

Author
Guest
Super Member
  • Total Posts : 80499
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
2004/03/02 11:53:48 (permalink)
0

help using if statement in MPLAB

Is it possible to use the 'if' statement in assembly language in MPLAB. when writing 'if' in MPLAB it turns blue which suggests to me that it is a valid instruction

if so i seem to be having problems with it. i am trying to code somewhere along the lines of:

if registerA == 0x31
goto Routine1
if registerA == 0x00
goto Routine2
else
goto Routine3
endif

anyway if i can not use the 'if' statement could someone suggest a way in which i could do this type of thing in assembly language.
#1

4 Replies Related Threads

    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: help using if statement in MPLAB 2004/03/02 12:11:42 (permalink)
    0
    OK i have found out that you can the if statement .

    the problem that i seem to be having is that when you use the if statement for example

    if registerA == 0x31

    is asking if the address of registerA is 0x31 then...; what i want to do is ask if the contents of registerA is 0x31 then ...

    what do i need to change in order to do this
    #2
    ric
    Super Member
    • Total Posts : 22098
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    RE: help using if statement in MPLAB 2004/03/02 14:55:16 (permalink)
    0
    You cannot use "if" to evaluate an expression while a program is running (= "run time").
    This is only useful for conditionlly inclusing some code at the time that the program is assembled.
    Remember that you are using an assembler, not a compiler. What you see is what you get, there is no "if" command in PIC assembler.

    You have to do an arithemtic instruction (like SUBWF or XORWF), then use one of the BTFSC or BTFSS intructions to conditionally skip an instruction (usually a GOTO). There are some pseudo instructions recognized by the assembler to write a test and GOTO as one instruction, e.g. "BZ" = branch on zero. Look in the MPLAB help file.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: help using if statement in MPLAB 2004/03/03 01:42:43 (permalink)
    0
    I suggest you to have a look at the instruction-set section of the datasheet, and use ONLY these instructions to code your project. At least the first one.

    If after that you want to use advanced options of the assembler as directives, macros, linker, etc. they can save you a lot of time. But I recommend you to start with the basics and get the picture of the system at its lowest level. Go a step each time, you'll learn better than trying to do it all the first time.

    Hope this helps,
    Vito.
    #4
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: help using if statement in MPLAB 2004/03/07 14:32:14 (permalink)
    0
    IF, #define, ELSE, DE, DW, CBLOCK, ENDC are all commands for the compiler.
    They are compile-time options!
    #5
    Jump to:
    © 2017 APG vNext Commercial Version 4.5