Page 31 - ARM Based Microcontroller Projects Using MBED
P. 31

2.3 EXAMPLES                               17























            FIG. 2.13  Calling subprogram DISPLAY.

            2.2.8 Calling a Subprogram
              A subprogram can be called from the main program or from another subprogram. In PDLs,
            a subprogram is called by using the keyword CALL, followed by the name of the subprogram.
            In flow charts it is common practice to insert vertical lines at the two sides of the box where the
            subprogram is called. Fig. 2.13 shows an example of where subprogram DISPLAY is called
            from a program.



                                            2.3 EXAMPLES

              Some simple examples are given in this section to show how the PDLs and their equivalent
            flow charts can be used in program development.

             EXAMPLE 2.1
             It is required to write a program to convert hexadecimal numbers “A” to “F” into decimals. Show the
             algorithm using a PDL and also draw the equivalent flow chart. Assume that the hexadecimal num-
             ber to be converted is called HEX_NUM, and the output decimal number is called DEC_NUM.
             Solution 2.1
             The required PDL is:
                 BEGIN
                     IF HEX_NUM ¼ “A” THEN
                          DEC_NUM ¼ 10
                     ELSE IF HEX_NUM ¼ “B” THEN
                          DEC_NUM ¼ 11
                     ELSE IF HEX_NUM ¼ “C” THEN
                          DEC_NUM ¼ 12
                     ELSE IF HEX_NUM ¼ “D” THEN
                          DEC_NUM ¼ 13
   26   27   28   29   30   31   32   33   34   35   36