         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program Name : BADD
    2  
    3  !*   Title      :  V.b    The IMP  BYTE ADDITION  Facilities
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Tests the byte addition and subtraction (both
    7  !*                 binary and unary) using various representations 
    8  !*                 and combinations of argument.  The arithmetic
    9  !*                 involves mostly binary operations.
   10  
   11  %Begin
   12  
   13     %string(255) param    { Used to get input from CLI}
   14  
   15     %Byte %Integer J
   16     %Byte %Integer K
   17     %Byte %Integer M
   18     %Byte %Integer N
   19  
   20     %Constant %Byte %Integer  CInt3 = 10
   21     %Constant %Byte %Integer  CInt4 = 3
   22           
   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     %Integer %Function  F
   38  
   39       !*  An extremely simple byte integer function that merely
   40       !*  returns the number THREE.  Note that this function 
   41       !*  does not presuppose parameter passing or expression
   42       !*  evaluation within functions.  It merely tests the
   43       !*  ability to encorporate functions within expressions. 
   44                                                             
   45       %Result = 3
   46  
   47      %End
   48  
   49  
   50  
   51     ! Code to find out where the output is to be sent
   52     ! -----------------------------------------------
   53     ! Where the output goes to depends on the parameter after the
   54     ! name used to run the program.
   55     !                       Parameter   |   Result
   56     !                       ------------|-------------
   57     !                     No parameter  |  No output
   58     !                          "s"      |  The screen
   59     !                          "j"      |  "journal"
   60     !                     anything else |  file name entered
   61  
   62     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
   63     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
   64  
   65     param=cliparam
   66           %if param = ""              %then select output (2) %c
   67+    %else %if param="s" %or param="S" %then select output(1) %c
   68+    %else %if param="j" %or param="J" %then open output(2,"journal") %and select output (2) %c
   69+    %else                                   open output(2,param)     %and select output (2)
   70     
   71  
   72  
   73  
   74     New Lines(2)
   75     Print String ("BYTE INTEGER Arithmetic Validation");   New Line
   76     Print String ("==================================");   New Lines (3)
   77  
   78  
   79  
   80     !*  Test the BYTE INTEGER ADDITION 
   81  
   82     !*  Test the ability to be assigned after a expression evaluation.
   83     !*  In each of the following six tests, the destination variable
   84     !*  is the same as one of the expression arguments.
   85  
   86  
   87     Print String ("Test BYTE INTEGER ADDITION.");  New Line
   88     Print String ("---------------------------");  New Line
   89  
   90     J = 50
   91     K = 10
   92  
   93     J = J + 10       { J = 60
   94     %If J = 60 %then pass %else fail
   95  
   96     J = 10 + J       { J = 70
   97     %If J = 70 %then pass %else fail
   98  
   99     J = J + CInt3    { J = 80
  100     %If J = 80 %then pass %else fail
  101  
  102     J = CInt3 + J    { J = 90
  103     %If J = 90 %then pass %else fail
  104  
  105     J = J + K       { J = 100
  106     %If J = 100 %then pass %else fail
  107  
  108     J = K + J        { J = 110
  109     %If J = 110 %then pass %else fail
  110  
  111     
  112     !*  Test that assignment after evaluation still works when the
  113     !*  destination variable does not appear in the expression.
  114  
  115     M = J + K    
  116     %If M = 120 %then pass %else fail
  117  
  118     
  119     !*  Now test the values of the two main variables: J and K
  120  
  121     %If J = 110 %and K = 10 %then pass %else fail
  122  
  123  
  124  
  125  
  126  
  127     !*  Test the BYTE INTEGER SUBTRACTION 
  128  
  129     !*  Test the ability to be assigned after a expression evaluation.
  130     !*  In each of the following six tests, the destination variable
  131     !*  is the same as one of the expression arguments.
  132  
  133     New Lines (2)
  134  
  135     Print String ("Test BYTE INTEGER SUBTRACTION.");   New Line
  136     Print String ("------------------------------");   New Line
  137  
  138     J = 110
  139     K = 10
  140     
  141     J = J - 10       { J = 100
  142     %If J = 100 %then pass %else fail
  143  
  144     J = 100 - J       { J = 0
  145     %If J = 0 %then pass %else fail
  146  
  147     J = 260 - CInt3    { J = 250
  148     %If J = 250 %then pass %else fail
  149  
  150     J = J - K       { J = 240
  151     %If J = 240 %then pass %else fail
  152  
  153  
  154     !*  Test that assignment after evaluation still works when the
  155     !*  destination variable does not appear in the expression.
  156  
  157     M = J - K    
  158     %If M = 230 %then pass %else fail
  159  
  160  
  161     !*  Now test the values of the two main variables: J and K
  162  
  163     %If J = 240 %and K = 10 %then pass %else fail
  164  
  165  
  166  
  167    
  168  
  169  
  170     !*  Test the UNARY MINUS operation.
  171  
  172     New Lines (2)
  173   
  174     Print String ("Test the UNARY MINUS");   New Line
  175     Print String ("--------------------");   New Lines (1)
  176  
  177     
  178     J = 50
  179     K = 10
  180  
  181     
  182     J = -(-J)
  183     %If J = 50 %then pass %else fail
  184  
  185     J = -50+J
  186     %If J = 0 %then pass %else fail
  187  
  188     J = -k+k
  189     %If J = 0 %then pass %else fail
  190  
  191     J = 30 + (-k)
  192     %If J = 20 %then pass %else fail
  193  
  194  
  195  
  196  select output(1)
  197  write(failures,1);  printstring(" failure(s)");  newline
  198     
  199     
  200  %End %of %Program
?F unused
?CINT4 unused
?N unused

   87 Statements compiled
