Keil Logo

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: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.