Page 248 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 248

8.2 Operators and Assignment Statements                              225


                                      unsigned char c,d[10];
                                      void fun{int a) { long b;
                                          b=l;
                                          c = dfa+b];
                                      }

            Some very powerful special operators are available in C. Table 8.2 shows the ones
        we use in this book. For each operator, an example is given together with its equivalent
        result using the simple operators of Table 8.2. The assignment operator = assigns the
        value on its right to the variable named on its left and returns the value it assigns so that
        value can be used in an expression to the left of the assignment operation: The example
        shows 0 is assigned to c, and that value (0) is assigned to b, and then that value is
        assigned to a. The increment operator + + can be used without an assignment operator
        (e.g., a++ just increments a). It can also be used in an expression in which it
        increments its operand after the former operand value is returned to be used in the
        expression. For example, b = a[i++] will use the old value of i as an index to put
        a[i] into b, then it will increment i. Similarly, the decrement operator -- can be
        used in expressions. If the + + or — appear in front of the variable, then the value
        returned by the expression is the updated value; a[++i] will first increment i, then
        use the incremented value as an index into a. The next row shows the use of the + and
        = operators used together to represent adding to a variable. The following rows show -
         | and & appended in front of = to represent subtracting from, ORing to, or ANDing to
        a variable. Shift « and » can be used in front of the = sign too. This form of a
        statement avoids the need to twice write the name of, and twice compute addresses for,
        the variable being added to or subtracted from. The last two rows of Table 8.2 show shift
        left and shift right operations and their equivalents in terms of elementary shift and
        assignment operators.
            A statement can be conditional, or it can involve looping to execute a sequence of
        statements that are written within it many times. We will discuss these control flow
        statements by giving the flow charts for them. See Figure 8.1 for conditional statements,
        8.2 for case statements, and 8.3 for loop statements. These simple standard forms appear
        throughout the rest of the book, and we will refer to them and their figures.

             Table 8.2. Special C Operators                Table 8.3.
                                                   Conditional Expression Operators
   243   244   245   246   247   248   249   250   251   252   253