         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program Name : BMULT
    2  
    3  !*   Title      :  VI.b    The IMP  BYTE  Facilities
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Tests the Multiplication, Division, Exponentiation and
    7  !*                 the REM function.
    8  
    9  %Begin
   10  
   11     %string(255) param    { Used to get input from CLI}
   12  
   13     %Integer X
   14  
   15     %Byte %Integer J 
   16     %Byte %Integer K 
   17     %Byte %Integer M
   18     %Byte %Integer P
   19     %Byte %Integer Q
   20  
   21     %Constant %Byte %Integer  CInt3 = 10
   22     %Constant %Byte %Integer  CInt4 = 3
   23  
   24  %owninteger failures=0
   25  
   26  %routine pass
   27    printstring("Pass")
   28    New Line
   29  %end
   30  %routine fail
   31    printstring("FAIL")
   32    New Line
   33    failures = failures+1
   34  %end
   35  
   36  
   37        
   38  
   39     %Byte %Integer %Function  F
   40  
   41       !*  An extremely simple byte integer function that merely
   42       !*  returns the number THREE.  Note that this function 
   43       !*  does not presuppose parameter passing or expression
   44       !*  evaluation within functions.  It merely tests the
   45       !*  ability to encorporate functions within expressions. 
   46                                                             
   47       %Result = 3
   48  
   49      %End
   50  
   51  
   52  
   53     ! Code to find out where the output is to be sent
   54     ! -----------------------------------------------
   55     ! Where the output goes to depends on the parameter after the
   56     ! name used to run the program.
   57     !                       Parameter   |   Result
   58     !                       ------------|-------------
   59     !                     No parameter  |  No output
   60     !                          "s"      |  The screen
   61     !                          "j"      |  "journal"
   62     !                     anything else |  file name entered
   63  
   64     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
   65     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
   66  
   67     param=cliparam
   68     %if param = "" %then select output (2) %c
   69+    %else %if param="s" %or param="S" %then select output(1) %c
   70+    %else %if param="j" %or param="J" %then  %c
   71+       open output(2,"journal") %and select output (2) %c
   72+    %else open output(2,param) %and select output (2)
   73     
   74  
   75  
   76  
   77     New Lines(2)
   78     Print String ("BYTE INTEGER Arithmetic Validation");   New Line
   79     Print String ("==================================");   New Lines (3)
   80  
   81  
   82  
   83     Print String ("Test the BYTE INTEGER Arithmetic Operators");  New Line
   84     Print String ("------------------------------------------");  New Line
   85  
   86  
   87  
   88  
   89     !*   Test the BYTE INTEGER MULTIPLICATION 
   90            
   91     !*  Test the ability to be assigned after a expression evaluation.
   92     !*  In each of the following six tests, the destination variable
   93     !*  is the same as one of the expression arguments. 
   94  
   95     New Lines (2)
   96  
   97     Print String ("Test BYTE INTEGER MULTIPLICATION.");   New Line
   98     Print String ("---------------------------------");   New Line
   99  
  100  
  101     J = 7
  102     K = 2
  103  
  104     J = J * 3       { J = 21
  105     %If J = 21 %then pass %else fail
  106  
  107     J = 2 * J       { J = 42
  108     %If J = 42 %then pass %else fail
  109  
  110     J = 5
  111     J = J * CInt3    { J = 50
  112     %If J = 50 %then pass %else fail
  113  
  114     J = 3
  115     J = CInt3 * J    { J = 30
  116     %If J = 30 %then pass %else fail
  117  
  118     J = J * K       { J = 60
  119     %If J = 60 %then pass %else fail
  120  
  121     J = J * K       { J = 120
  122     %If J = 120 %then pass %else fail
  123  
  124     
  125     !*  Test that assignment after evaluation still works when the
  126     !*  destination variable does not appear in the expression.
  127  
  128     J = 5
  129  
  130     M = J * K    
  131     %If M = 10 %then pass %else fail
  132  
  133     
  134     !*  Now test the values of the two main variables: J and K
  135  
  136     %If J = 5 %and K = 2 %then pass %else fail
  137  
  138  
  139  
  140  
  141  
  142     !*    BYTE INTEGER EXPONENTIATION
  143  
  144     New Lines (2)
  145  
  146     Print String ("Test BYTE INTEGER EXPONENTIATION.");  New Line
  147     Print String ("---------------------------------");  New Line
  148  
  149     K = 3
  150     M = 5
  151  
  152     J = K ^^ 0
  153     %If J = 1 %then pass %else fail
  154  
  155     J = K ^^ M
  156     %If J = 243 %then pass %else fail
  157  
  158     J = K ^^ CInt4
  159     %If J = 27 %then pass %else fail
  160  
  161     J = 3 ^^ 0
  162     %If J = 1 %then pass %else fail
  163  
  164     J = 3 ^^ M
  165     %If J = 243 %then pass %else fail
  166  
  167     J = 3 ^^ CInt4
  168     %If J = 27 %then pass %else fail
  169  
  170     J = CInt4 ^^ 0
  171     %If J = 1 %then pass %else fail
  172  
  173     J = CInt4 ^^ M
  174     %If J = 243 %then pass %else fail
  175  
  176     J = CInt4 ^^ CInt4
  177     %If J = 27 %then pass %else fail
  178     
  179  
  180     New Line
  181     Print String ("Let:  J = 3  before every test with J as argument."); New Line
  182     Print String ("---") ; New Line
  183  
  184     J = 3
  185     J = J ^^ 0
  186     %If J = 1 %then pass %else fail
  187  
  188     J = 3
  189     J = J ^^ M
  190     %If J = 243 %then pass %else fail
  191  
  192     J = 3
  193     J = J ^^ Cint4
  194     %If J = 27 %then pass %else fail
  195  
  196     J = 3
  197     J = J ^^ J
  198     %If J = 27 %then pass %else fail
  199  
  200   
  201   
  202  
  203     !*    BYTE INTEGER Division
  204  
  205     New Lines (2)
  206  
  207     Print String ("Test BYTE INTEGER Division.");  New Line
  208     Print String ("---------------------------");  New Line
  209  
  210     K = 30
  211     M = 5
  212  
  213     
  214     J = K // M
  215     %If J = 6 %then pass %else fail
  216  
  217     J = K // CInt4
  218     %If J = 10 %then pass %else fail
  219  
  220     J = 30 // M
  221     %If J = 6 %then pass %else fail
  222  
  223     J = 30 // CInt4
  224     %If J = 10 %then pass %else fail
  225  
  226     J = CInt3 // M
  227     %If J = 2 %then pass %else fail
  228  
  229     J = CInt3 // CInt4
  230     %If J = 3 %then pass %else fail
  231     
  232     New Line
  233     Print String ("Let:  J = 30  before every test with J as argument."); New Line
  234     Print String ("---")
  235     New Line
  236  
  237     J = 30
  238     J = J // M
  239     %If J = 6 %then pass %else fail
  240  
  241     J = 30
  242     J = J // Cint4
  243     %If J = 10 %then pass %else fail
  244  
  245     J = 30
  246     J = J // J
  247     %If J = 1 %then pass %else fail
  248  
  249     J = M // M
  250     %If J = 1 %then pass %else fail
  251  
  252  
  253  
  254  
  255     New Lines (2)
  256  
  257     Print String ("Test the Modulus Operator");  New Line
  258     Print String ("-------------------------");  New Line
  259     
  260     K = 0
  261     X = -3       { X is an integer
  262     P = 3
  263  
  264     J = |-3|
  265     Q = |3|
  266     %if J = 3 %then pass %else fail
  267     %if Q = 3 %then pass %else fail
  268     
  269     J = |CInt4|
  270     %if J = 3 %then pass %else fail
  271  
  272     J = |K|
  273     %if J = 0 %then pass %else fail
  274  
  275     J = |X|
  276     %if J = 3 %then pass %else fail
  277  
  278     J = |P|
  279     %if J = 3 %then pass %else fail
  280  
  281     P = |P|
  282     %if P = 3 %then pass %else fail
  283  
  284     J = |F|
  285     %if J = 3 %then pass %else fail
  286  
  287     J = |(|X|)|
  288     %if J = 3 %then pass %else fail
  289  
  290     J = |(-P) + K - (|F * X|)|
  291     %if J = 12 %then pass %else fail
  292  
  293  
  294  select output(1)
  295  write(failures,1);  printstring(" failure(s)");  newline
  296  
  297  %End %of %Program

  169 Statements compiled
