       ͻ
        Lesson 6 Part 010  F-PC 3.5 Tutorial by Jack Brown 
       ͼ

                  Ŀ
                     Topics for Lesson 6   
                  

          0) Review of Lesson 5
          1) Forth String Primitives
          2) Numeric Output Formatting.
          3) COMPILE [COMPILE] and IMMEDIATE
          4) Simple String Package.
          5) Case  Statement
          6) Line Editor Case Study.

         Ŀ
           Review of the */ , "star-slash" scalar. 
         

*/  ( a b c -- ab/c )

Perform multiplication and then division. Star-slash multiplies 16-bit
a  and  16-bit  b  to form a 32-bit intermediate result which is then
divided by 16-bit c to give a 16-bit result.  The 32-bit intermediate
product ensures accurate results when multiplying by fractions. We use
*/  to multiply a  by the fraction b/c

Examples:
 32-bit intermediate product results in correct answer.
 15000   3   4  */      gives   11250     correct answer
 16-bit intermediate product results in overflow and the
 15000   3   *  4 /     gives   -5134     wrong   answer

           Ŀ
             Review of the */MOD Scalar  
           

The "star-slash-mod", scalar and its application to rounding fractions.

 */MOD  ( a b c -- r q )

Compute ab/c with 32-bit intermediate product ab  and leave
quotient q and remainder r .  Note:  Forth-83 */MOD uses
signed values  a b c  and uses floored division.

Rounding calculations that involve division.
: %R1    10 */     5 +            10 /  .    ;
: %R2    50 */     1+             2/    .    ;
: %R3   100 */MOD  SWAP 50 +  100 / +   .    ;
: %R4   100 */MOD  SWAP 49 > NEGATE +   .    ;

\ Fractions:  see Brodie page 125 for more.
: *PI       355     113 */ ;
: *SQRT(2)  19601 13860 */ ;
: *E        28667 10546 */ ;

          Ŀ
             Review of Infinite and Indefinite Loops.  
          

The infinite loop with no exit.
     ... (step 1)  BEGIN   (step2)  AGAIN   (step3) ...

The infinite loop with EXIT  escape hatch.
   ... (s1) BEGIN (s2)
                  (condition) IF EXIT THEN
                  (s3)
            AGAIN (s4) ...

Indefinite Loops
    ... (s1)  BEGIN   (s2)
                     (condition)
              UNTIL   (s3) ...


 ... (s1)  BEGIN  (s2)
                  (condition)
           WHILE  (s3)
           REPEAT (s4) ...

         Ŀ
            Review of Do Loops  
         

  ... (s1)  l i   DO  (s2)      LOOP  (s3) ...
  ... (s1)  l i   DO  (s2)  n  +LOOP  (s3) ...
  ... (s1)  l i  ?DO  (s2)      LOOP  (s3) ...
  ... (s1)  l i  ?DO  (s2)  n  +LOOP  (s3) ...

        Ŀ
           Leaving Loops early.  
        

  (s1)  l i   DO    (s2)
                    (condition) IF  (s3) LEAVE THEN
                    (s4)
              LOOP  (s5) ...

This is an alternative form if step 3 is not required.

  (s1)  l i   DO    (s2)
                    (condition) ?LEAVE
                    (s4)
              LOOP  (s5) ...

Ŀ
   Please Move to Lesson 6 Part 020  

