UMBC CMSC 211

UMBC | CSEE


Generally Applicable IFs

In C, we can have something like:
#ifdef DEBUG
    printf( "At debug point 27: \n" );
	printf( " A = %d\n", A );
    printf( " B = %d\n", B );
#endif
  
There is also a #elif and a #ifndef to give it more power!

That allows us to compile the block of code based on some condition. It has wide usage and is a very handy technique.

In assembly language, we have something similiar as:

IF condition
    ... lines assembled if 'condition' is true
ELSE
    ... lines assembled if 'condition' is false
ENDIF
  
and even:
IF condition1
    ... lines assembled if 'condition1' is true
ELSEIF condition2
    ... lines assembled if 'condition1' is false and 'condition2' is true
ELSEIF condition3
    ... lines assembled if 'condition1' is false and 'condition2' is false and 'condition3' is true
ELSE
    ... lines assembled if 'condition1' and 'condition2' and 'condition3' are false
ENDIF
  
What you have to understand about the above example, is that of the four possibilities, only one will end up in your assembled program. That makes your program smaller and faster.

Your condition might be:

con EQ 1 Where did con get a value? Two ways, an EQUate: CON EQU 1 or from the command line: masm /Dcon=whatever or ml /symbol=value

Actually, we have even more:

Directive     Description

IF            Assembles block if expression is true (nonzero)
IFE           Assembles block if expression is false (zero)
IFB           Assembles block if expression is blank
IFNB          Assembles block if expression is not blank
IFDEF         Assembles block if symbol is defined
IFNDEF        Assembles block if symbol is not defined
IFDIF         Assembles block if arguments are different
IFDIFI        Assembles block if arguments are different, case insensitive
IFIDN         Assembles block if arguments are identical
IFIDNI        Assembles block if arguments are identical, case insensitive

ELSE          Begins alternate conditional block
ELSEIF        Begins alternate block with a new condition
ENDIF         Ends conditional block

There are ELSE versions of each IF condition:

  ELSEIF,    ELSEIFB,    ELSEIFDEF,    ELSEIFDIF, ELSEIFDIFI, ELSEIFE,
  ELSEIFIDN, ELSEIFIDNI, ELSEIFNB, and ELSEIFNDEF

In C, when we are including a bunch of header files, you will ofthen see something like:

#ifndef __GARY_HEADER__
#define __GARY_HEADER__
...some stuff here
#endif
  
In Assembly, we would have the equivalent:
IFNDEF ABC_Included
         ... some stuff here
  ABC_Included EQU 0
ENDIF
  
For the conditions, we have the following operators:
EQ	EQual
NE	Not Equal
LT	Less Than
LE	Les than or Equal to
GT	Greater Than
GE	Greater than or Equal to


UMBC | CSEE