Keil™, An ARM® Company

Technical Support

A51: DIFFERENCE BETWEEN IF AND $IF


Information in this article applies to:

  • C51 All Versions

QUESTION

What's the difference between the $IF and IF conditional statements?

ANSWER

The primary difference between $IF and IF is the defined names or symbols that may be tested. In assembler, there are several ways to define symbols.

  • $SET or $RESET (or using SET or RESET on the command line).
  • EQU.
  • LIT.
  • SET (not the same as $SET).
  • and a defined label.

The $IF statement may only be used to test symbols defined with $SET or $RESET within the program or on the command line.

The IF statement may only be used to test symbols defined with EQU, LIT, or SET, or labels with an absolute address. IF may not be used to test symbols defined with $SET or $RESET.

For example:

$set    (var1=1)
var2    equ     2
var3    lit     '3'   ;This works only on AX51
var4    set     4

dseg at 5
var5: ds 1

$if (var1 eq 1)
  __error__ "1"
$endif

if (var2 eq 2)
  __error__ "2"
endif

if (var3 eq 3)
  __error__ "3"
endif

if (var4 eq 4)
  __error__ "4"
endif

if (var5 ge 5)
  __error__ "5"
endif

SEE ALSO

Last Reviewed: Monday, June 07, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure