         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program Name : Logic
    2  
    3  !*   Title      :  XV     Logic                      
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Test the bit vector facilities that use logical operators
    7  
    8  %Begin
    9  
   10     %string(255) param    { Used to get input from CLI}
   11  
   12     !*  Note that some of the following bit maps are variable
   13     !*  and some are constant.  This allows us to test both 
   14     !*  in the logical operators.
   15  
   16     %Constant %Integer  Bits1 = 2_00000000000000000000000000000000
   17               %Integer  Bits2 = 2_01010101010101010101010101010101
   18     %Constant %Integer  Bits3 = 2_00001111000011110000111100001111
   19               %Integer  Bits4 = 2_11111111111111111111111111111111
   20               %Integer  Bits5 = 2_10110111100001010011110010101000
   21     %Constant %Integer  Bits6 = 2_00100110111100101010100111110111
   22               %Integer  LMask = 2_10000000000000000000000000000000
   23               %Integer  RMask = 2_00000000000000000000000000000001
   24  
   25  
   26  %owninteger failures=0
   27  
   28  %routine pass
   29    printstring("Pass")
   30    New Line
   31  %end
   32  %routine fail
   33    printstring("FAIL")
   34    New line
   35    failures = failures+1
   36  %end
   37     
   38  
   39  
   40     ! Code to find out where the output is to be sent
   41     ! -----------------------------------------------
   42     ! Where the output goes to depends on the parameter after the
   43     ! name used to run the program.
   44     !                       Parameter   |   Result
   45     !                       ------------|-------------
   46     !                     No parameter  |  No output
   47     !                          "s"      |  The screen
   48     !                          "j"      |  "journal"
   49     !                     anything else |  file name entered
   50  
   51     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
   52     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
   53  
   54     param=cliparam
   55     %if param = "" %then select output (2) %c
   56+    %else %if param="s" %or param="S" %then select output(1) %c
   57+    %else %if param="j" %or param="J" %then  %c
   58+       open output(2,"journal") %and select output (2) %c
   59+    %else open output(2,param) %and select output (2)
   60     
   61  
   62     New Lines(2)
   63     Print String ("Logical Operation Validation");   New Line
   64     Print String ("============================");   New Lines (3)
   65  
   66  
   67  
   68     Print String ("Test the Bit Vector Operations.");   New Line
   69     Print String ("-------------------------------");   New Line
   70  
   71  
   72     %if bits1=0 %then pass %else fail
   73     %if bits2=1431655765 %then pass %else fail
   74     %if bits3=252645135 %then pass %else fail
   75     %if bits4=-1 %then pass %else fail
   76  
   77     !*  Test the Logical AND
   78  
   79     %if bits2 & bits3=84215045 %then pass %else fail
   80  
   81     !*  Test the Logical Inclusive OR
   82  
   83     %if bits2 ! bits3 = 1600085855 %then pass %else fail
   84  
   85     !*  Test the Logical Exclusive OR
   86  
   87     %if bits2!!bits3 = 1515870810 %then pass %else fail
   88  
   89     !*  Test the Logical Unary NOT
   90  
   91     %if \bits2 = -1431655766 %then pass %else fail
   92  
   93     !*  Test the Left Shift
   94  
   95     %if bits3 << 4 = -252645136 %then pass %else fail
   96  
   97     !*  Test the Right Shift
   98  
   99     %if bits2 >> 4 = 89478485 %then pass %else fail
  100  
  101     New Lines (2)
  102  
  103  
  104     !*     Test the priority of the operators
  105  
  106     Print String ("Test the Precedence of the Logical Operators.");  New Line
  107     Print String ("---------------------------------------------");  New Line
  108  
  109     %if ((((\Bits6) & (Bits3 >> 6)) !! Bits5)) = (\Bits6 & Bits3 >> 6 !! Bits5) %c
  110+    %then pass %else fail
  111  
  112     %if ((\Bits6) & Bits5) = (\Bits6 & Bits5) %then pass %else fail
  113  
  114     %if ((\Bits5) >> 5) = (\Bits5 >> 5) %then pass %else fail
  115  
  116     %if ((\Bits6) ! Bits5) = (\Bits6 ! Bits5) %then pass %else fail
  117  
  118     %if ((\Bits6) !! Bits5) = (\Bits6 !! Bits5) %then pass %else fail
  119  
  120     %if (Bits6 & (Bits5 >> 4)) = (Bits6 & Bits5 >> 4) %then pass %else fail
  121  
  122     %if (Bits6 ! (Bits5 >> 4)) = (Bits6 ! Bits5 >> 4) %then pass %else fail
  123  
  124     %if (Bits6 !! (Bits5 >> 4)) = (Bits6 !! Bits5 >> 4) %then pass %else fail
  125  
  126     %if (Bits6 & (Bits5 << 4)) = (Bits6 & Bits5 << 4) %then pass %else fail
  127  
  128     %if (Bits6 ! (Bits5 << 4)) = (Bits6 ! Bits5 << 4) %then pass %else fail
  129  
  130     %if (Bits6 !! (Bits5 << 4)) = (Bits6 !! Bits5 << 4) %then pass %else fail
  131  
  132     %if (Bits6 ! (Bits5 & Bits3)) = (Bits6 ! Bits5 & Bits3)   %then pass %else fail
  133  
  134     %if (Bits6 !! (Bits5 & Bits3)) = (Bits6 !! Bits5 & Bits3)   %then pass %else fail
  135  
  136     %if ((Bits6 ! Bits5) !! Bits3) = (Bits6 ! Bits5 !! Bits3) %then pass %else fail
  137  
  138     %if ((Bits6 !! Bits5) ! Bits3) = (Bits6 !! Bits5 ! Bits3) %then pass %else fail
  139  
  140  
  141  
  142  
  143     !*   Assorted Tests on the Logical Operators
  144  
  145     New Lines (2)
  146     Print String ("Assorted Tests on the Logical Operators.");  New Line
  147     Print String ("----------------------------------------");  New Line
  148  
  149  
  150     %If  Bits6 !! Bits3 !! Bits3 = Bits6 %then pass %else fail
  151  
  152     %If  \(\Bits6) = Bits6 %then pass %else fail
  153     
  154     %If  \Bits1 = Bits4 %then pass %else fail
  155     
  156     %If (RMask >> 10) << 10 = RMask %then fail %else pass
  157     
  158     %If  (LMask >> 10) << 10 = LMask %then pass %else fail
  159     
  160     %If Bits6 >> 0 = Bits6 << 0 %then pass %else fail
  161     
  162     
  163  
  164  select output(1)
  165  write(failures,1);  printstring(" failure(s)");  newline
  166  %End %of %Program

   77 Statements compiled
