Crossware

Table of Contents        Previous topic       Next topic       

CROSS ASSEMBLER->Structured Assembly->IF/THEN/ELSE/ENDI

The IF/THEN/ELSE/ENDI construct will generate code that selects whether or not your enclosed assembler code will be executed.  The ELSE is optional.

The construct without the ELSE is:

     IF.<size> <expression> THEN.<distance>
     <your assembly code>
     ENDI

The construct with the ELSE is:

     IF.<size> <expression> THEN.<distance>
     <your assembly code>
     ELSE.<distance>
     <your assembly code>
     ENDI

<size> can be .B, .W or .L and the assembler will use this size when it generates the compare instructions.  If no size is specified, the assembler will assume .W.  However if either of the operands of a pair is an address register, the size of the compare will always be .L.

<distance> can be .S, .W and for chips that support long branches .L.  The assembler will use this when it generates code for forward branches.  For ELSE the distance must be present since the assembler uses the dot to distinguish this structured assembly ELSE from an alternative use of ELSE.

<expression> can be:

<subexpression>
<subexpression> AND <subexpression>
<subexpression> OR <subexpression>

<subexpression> can be:

<condition>
<operand> <condition> <operand>

<condition> can be one of:

<CC><CS><EQ><GE><GT>
<HI><LE><LS><LT><MI>
<NE><PL><VC><VS>
<operand> is a valid microprocessor instruction operand such as D3, (A4), (A4)+.

The operands of a sub-expression must be compatible with each other that a valid compare instruction can be generated.

Example 1:

    IF.L <CC> THEN.S
      <your assembly code>
    ELSE.S
    <your assembly code>
    ENDI

will generate the following assembler code:

         BCS.S     .00000
         <your assembly code>
         BRA.S     .00001
.00000
         <your assembly code>
.00001

Example 2:

    IF.L D1 <EQ> (A1) THEN.S
      <your assembly code>
    ELSE.S
    <your assembly code>
    ENDI

will generate the following assembler code:

          CMP.L     (A1),D1
          BNE.S     .00000
          <your assembly code>
          ELSE      .S
          BRA.S     .00001
.00000
          <your assembly code>
          ENDI
.00001

Example 3:

    IF.L D1 <EQ> (A1) AND D1 <NE> #35 THEN.S
    <your assembly code>
    ELSE.S
    <your assembly code>
    ENDI

will generate the following assembler code:

         CMP.L     (A1),D1
         BNE.S     .00000
         CMP.L     #35,D1
         BEQ.S     .00000
         <your assembly code>
         BRA.S     .00001
.00000
         <your assembly code>
.00001