#include <perms.h>

                                                                //      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
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     10  
                                                                //     11     %string(255) param    { Used to get input from CLI}
_imp_string /*%string(255)*/ PARAM;
                                                                //     12  
                                                                //     13     %Integer X
int X;
                                                                //     14  
                                                                //     15     %Byte %Integer J 
unsigned char J;
                                                                //     16     %Byte %Integer K 
unsigned char K;
                                                                //     17     %Byte %Integer M
unsigned char M;
                                                                //     18     %Byte %Integer P
unsigned char P;
                                                                //     19     %Byte %Integer Q
unsigned char Q;
                                                                //     20  
                                                                //     21     %Constant %Byte %Integer  CInt3 = 10
                                                                //     22     %Constant %Byte %Integer  CInt4 = 3
                                                                //     23  
                                                                //     24  %owninteger failures=0
static int FAILURES = 0;
                                                                //     25  
                                                                //     26  %routine pass
void PASS( void )
{
                                                                //     27    printstring("Pass")
_imp_PRINTSTRING(_imp_str_literal("Pass"));
                                                                //     28    New Line
_imp_NEWLINE();
                                                                //     29  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block PASS at level 2
                                                                //     30  %routine fail
void FAIL( void )
{
                                                                //     31    printstring("FAIL")
_imp_PRINTSTRING(_imp_str_literal("FAIL"));
                                                                //     32    New Line
_imp_NEWLINE();
                                                                //     33    failures = failures+1
FAILURES = (((int)(FAILURES)) + (1));
                                                                //     34  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block FAIL at level 2
                                                                //     35  
                                                                //     36  
                                                                //     37        
                                                                //     38  
                                                                //     39     %Byte %Integer %Function  F
unsigned char F( void )
{
                                                                //     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
/* Remove %on %event handler here if present for this block */
return 3;
                                                                //     48  
                                                                //     49      %End
} // End of block F at level 2
                                                                //     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
PARAM = _imp_CLIPARAM();
                                                                //     68     %if param = "" %then select output (2) %c
if ((_imp_strcmp(PARAM, _imp_str_literal("")) != 0)) goto L_0002;
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0002:;
if ((_imp_strcmp(PARAM, _imp_str_literal("s")) == 0)) goto L_0004;
if ((_imp_strcmp(PARAM, _imp_str_literal("S")) != 0)) goto L_0005;
L_0004:;
_imp_SELECTOUTPUT(1);
goto L_0003;
L_0005:;
if ((_imp_strcmp(PARAM, _imp_str_literal("j")) == 0)) goto L_0006;
if ((_imp_strcmp(PARAM, _imp_str_literal("J")) != 0)) goto L_0007;
L_0006:;
_imp_OPENOUTPUT(2, _imp_str_literal("journal"));
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0007:;
_imp_OPENOUTPUT(2, PARAM);
_imp_SELECTOUTPUT(2);
L_0003:;
                                                                //     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)
_imp_NEWLINES(2);
                                                                //     78     Print String ("BYTE INTEGER Arithmetic Validation");   New Line
_imp_PRINTSTRING(_imp_str_literal("BYTE INTEGER Arithmetic Validation"));
_imp_NEWLINE();
                                                                //     79     Print String ("==================================");   New Lines (3)
_imp_PRINTSTRING(_imp_str_literal("=================================="));
_imp_NEWLINES(3);
                                                                //     80  
                                                                //     81  
                                                                //     82  
                                                                //     83     Print String ("Test the BYTE INTEGER Arithmetic Operators");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test the BYTE INTEGER Arithmetic Operators"));
_imp_NEWLINE();
                                                                //     84     Print String ("------------------------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("------------------------------------------"));
_imp_NEWLINE();
                                                                //     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)
_imp_NEWLINES(2);
                                                                //     96  
                                                                //     97     Print String ("Test BYTE INTEGER MULTIPLICATION.");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test BYTE INTEGER MULTIPLICATION."));
_imp_NEWLINE();
                                                                //     98     Print String ("---------------------------------");   New Line
_imp_PRINTSTRING(_imp_str_literal("---------------------------------"));
_imp_NEWLINE();
                                                                //     99  
                                                                //    100  
                                                                //    101     J = 7
J = 7;
                                                                //    102     K = 2
K = 2;
                                                                //    103  
                                                                //    104     J = J * 3       { J = 21
J = (((int)(J)) * (3));
                                                                //    105     %If J = 21 %then pass %else fail
if (((J) != (21))) goto L_0008;
PASS();
goto L_0009;
L_0008:;
FAIL();
L_0009:;
                                                                //    106  
                                                                //    107     J = 2 * J       { J = 42
J = ((2) * ((int)(J)));
                                                                //    108     %If J = 42 %then pass %else fail
if (((J) != (42))) goto L_000a;
PASS();
goto L_000b;
L_000a:;
FAIL();
L_000b:;
                                                                //    109  
                                                                //    110     J = 5
J = 5;
                                                                //    111     J = J * CInt3    { J = 50
J = (((int)(J)) * (10));
                                                                //    112     %If J = 50 %then pass %else fail
if (((J) != (50))) goto L_000c;
PASS();
goto L_000d;
L_000c:;
FAIL();
L_000d:;
                                                                //    113  
                                                                //    114     J = 3
J = 3;
                                                                //    115     J = CInt3 * J    { J = 30
J = ((10) * ((int)(J)));
                                                                //    116     %If J = 30 %then pass %else fail
if (((J) != (30))) goto L_000e;
PASS();
goto L_000f;
L_000e:;
FAIL();
L_000f:;
                                                                //    117  
                                                                //    118     J = J * K       { J = 60
J = (((unsigned char)(J)) * (K));
                                                                //    119     %If J = 60 %then pass %else fail
if (((J) != (60))) goto L_0010;
PASS();
goto L_0011;
L_0010:;
FAIL();
L_0011:;
                                                                //    120  
                                                                //    121     J = J * K       { J = 120
J = (((unsigned char)(J)) * (K));
                                                                //    122     %If J = 120 %then pass %else fail
if (((J) != (120))) goto L_0012;
PASS();
goto L_0013;
L_0012:;
FAIL();
L_0013:;
                                                                //    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
J = 5;
                                                                //    129  
                                                                //    130     M = J * K    
M = (((unsigned char)(J)) * (K));
                                                                //    131     %If M = 10 %then pass %else fail
if (((M) != (10))) goto L_0014;
PASS();
goto L_0015;
L_0014:;
FAIL();
L_0015:;
                                                                //    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
if (((J) != (5))) goto L_0016;
if (((K) != (2))) goto L_0016;
PASS();
goto L_0017;
L_0016:;
FAIL();
L_0017:;
                                                                //    137  
                                                                //    138  
                                                                //    139  
                                                                //    140  
                                                                //    141  
                                                                //    142     !*    BYTE INTEGER EXPONENTIATION
                                                                //    143  
                                                                //    144     New Lines (2)
_imp_NEWLINES(2);
                                                                //    145  
                                                                //    146     Print String ("Test BYTE INTEGER EXPONENTIATION.");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test BYTE INTEGER EXPONENTIATION."));
_imp_NEWLINE();
                                                                //    147     Print String ("---------------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("---------------------------------"));
_imp_NEWLINE();
                                                                //    148  
                                                                //    149     K = 3
K = 3;
                                                                //    150     M = 5
M = 5;
                                                                //    151  
                                                                //    152     J = K ^^ 0
J = _imp_IEXP(K, 0);
                                                                //    153     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0018;
PASS();
goto L_0019;
L_0018:;
FAIL();
L_0019:;
                                                                //    154  
                                                                //    155     J = K ^^ M
J = _imp_IEXP(K, M);
                                                                //    156     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_001a;
PASS();
goto L_001b;
L_001a:;
FAIL();
L_001b:;
                                                                //    157  
                                                                //    158     J = K ^^ CInt4
J = _imp_IEXP(K, 3);
                                                                //    159     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_001c;
PASS();
goto L_001d;
L_001c:;
FAIL();
L_001d:;
                                                                //    160  
                                                                //    161     J = 3 ^^ 0
J = _imp_IEXP(3, 0);
                                                                //    162     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_001e;
PASS();
goto L_001f;
L_001e:;
FAIL();
L_001f:;
                                                                //    163  
                                                                //    164     J = 3 ^^ M
J = _imp_IEXP(3, M);
                                                                //    165     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_0020;
PASS();
goto L_0021;
L_0020:;
FAIL();
L_0021:;
                                                                //    166  
                                                                //    167     J = 3 ^^ CInt4
J = _imp_IEXP(3, 3);
                                                                //    168     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_0022;
PASS();
goto L_0023;
L_0022:;
FAIL();
L_0023:;
                                                                //    169  
                                                                //    170     J = CInt4 ^^ 0
J = _imp_IEXP(3, 0);
                                                                //    171     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0024;
PASS();
goto L_0025;
L_0024:;
FAIL();
L_0025:;
                                                                //    172  
                                                                //    173     J = CInt4 ^^ M
J = _imp_IEXP(3, M);
                                                                //    174     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_0026;
PASS();
goto L_0027;
L_0026:;
FAIL();
L_0027:;
                                                                //    175  
                                                                //    176     J = CInt4 ^^ CInt4
J = _imp_IEXP(3, 3);
                                                                //    177     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_0028;
PASS();
goto L_0029;
L_0028:;
FAIL();
L_0029:;
                                                                //    178     
                                                                //    179  
                                                                //    180     New Line
_imp_NEWLINE();
                                                                //    181     Print String ("Let:  J = 3  before every test with J as argument."); New Line
_imp_PRINTSTRING(_imp_str_literal("Let:  J = 3  before every test with J as argument."));
_imp_NEWLINE();
                                                                //    182     Print String ("---") ; New Line
_imp_PRINTSTRING(_imp_str_literal("---"));
_imp_NEWLINE();
                                                                //    183  
                                                                //    184     J = 3
J = 3;
                                                                //    185     J = J ^^ 0
J = _imp_IEXP(J, 0);
                                                                //    186     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_002a;
PASS();
goto L_002b;
L_002a:;
FAIL();
L_002b:;
                                                                //    187  
                                                                //    188     J = 3
J = 3;
                                                                //    189     J = J ^^ M
J = _imp_IEXP(J, M);
                                                                //    190     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_002c;
PASS();
goto L_002d;
L_002c:;
FAIL();
L_002d:;
                                                                //    191  
                                                                //    192     J = 3
J = 3;
                                                                //    193     J = J ^^ Cint4
J = _imp_IEXP(J, 3);
                                                                //    194     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_002e;
PASS();
goto L_002f;
L_002e:;
FAIL();
L_002f:;
                                                                //    195  
                                                                //    196     J = 3
J = 3;
                                                                //    197     J = J ^^ J
J = _imp_IEXP(J, J);
                                                                //    198     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_0030;
PASS();
goto L_0031;
L_0030:;
FAIL();
L_0031:;
                                                                //    199  
                                                                //    200   
                                                                //    201   
                                                                //    202  
                                                                //    203     !*    BYTE INTEGER Division
                                                                //    204  
                                                                //    205     New Lines (2)
_imp_NEWLINES(2);
                                                                //    206  
                                                                //    207     Print String ("Test BYTE INTEGER Division.");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test BYTE INTEGER Division."));
_imp_NEWLINE();
                                                                //    208     Print String ("---------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("---------------------------"));
_imp_NEWLINE();
                                                                //    209  
                                                                //    210     K = 30
K = 30;
                                                                //    211     M = 5
M = 5;
                                                                //    212  
                                                                //    213     
                                                                //    214     J = K // M
J = (long)((long)((unsigned char)(K)) / (long)((unsigned char)(_Z(M))));
                                                                //    215     %If J = 6 %then pass %else fail
if (((J) != (6))) goto L_0032;
PASS();
goto L_0033;
L_0032:;
FAIL();
L_0033:;
                                                                //    216  
                                                                //    217     J = K // CInt4
J = (long)((long)((unsigned char)(K)) / (long)((int)(3)));
                                                                //    218     %If J = 10 %then pass %else fail
if (((J) != (10))) goto L_0034;
PASS();
goto L_0035;
L_0034:;
FAIL();
L_0035:;
                                                                //    219  
                                                                //    220     J = 30 // M
J = (long)((long)((int)(30)) / (long)((unsigned char)(_Z(M))));
                                                                //    221     %If J = 6 %then pass %else fail
if (((J) != (6))) goto L_0036;
PASS();
goto L_0037;
L_0036:;
FAIL();
L_0037:;
                                                                //    222  
                                                                //    223     J = 30 // CInt4
J = (long)((long)((int)(30)) / (long)((int)(3)));
                                                                //    224     %If J = 10 %then pass %else fail
if (((J) != (10))) goto L_0038;
PASS();
goto L_0039;
L_0038:;
FAIL();
L_0039:;
                                                                //    225  
                                                                //    226     J = CInt3 // M
J = (long)((long)((int)(10)) / (long)((unsigned char)(_Z(M))));
                                                                //    227     %If J = 2 %then pass %else fail
if (((J) != (2))) goto L_003a;
PASS();
goto L_003b;
L_003a:;
FAIL();
L_003b:;
                                                                //    228  
                                                                //    229     J = CInt3 // CInt4
J = (long)((long)((int)(10)) / (long)((int)(3)));
                                                                //    230     %If J = 3 %then pass %else fail
if (((J) != (3))) goto L_003c;
PASS();
goto L_003d;
L_003c:;
FAIL();
L_003d:;
                                                                //    231     
                                                                //    232     New Line
_imp_NEWLINE();
                                                                //    233     Print String ("Let:  J = 30  before every test with J as argument."); New Line
_imp_PRINTSTRING(_imp_str_literal("Let:  J = 30  before every test with J as argument."));
_imp_NEWLINE();
                                                                //    234     Print String ("---")
_imp_PRINTSTRING(_imp_str_literal("---"));
                                                                //    235     New Line
_imp_NEWLINE();
                                                                //    236  
                                                                //    237     J = 30
J = 30;
                                                                //    238     J = J // M
J = (long)((long)((unsigned char)(J)) / (long)((unsigned char)(_Z(M))));
                                                                //    239     %If J = 6 %then pass %else fail
if (((J) != (6))) goto L_003e;
PASS();
goto L_003f;
L_003e:;
FAIL();
L_003f:;
                                                                //    240  
                                                                //    241     J = 30
J = 30;
                                                                //    242     J = J // Cint4
J = (long)((long)((unsigned char)(J)) / (long)((int)(3)));
                                                                //    243     %If J = 10 %then pass %else fail
if (((J) != (10))) goto L_0040;
PASS();
goto L_0041;
L_0040:;
FAIL();
L_0041:;
                                                                //    244  
                                                                //    245     J = 30
J = 30;
                                                                //    246     J = J // J
J = (long)((long)((unsigned char)(J)) / (long)((unsigned char)(_Z(J))));
                                                                //    247     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0042;
PASS();
goto L_0043;
L_0042:;
FAIL();
L_0043:;
                                                                //    248  
                                                                //    249     J = M // M
J = (long)((long)((unsigned char)(M)) / (long)((unsigned char)(_Z(M))));
                                                                //    250     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0044;
PASS();
goto L_0045;
L_0044:;
FAIL();
L_0045:;
                                                                //    251  
                                                                //    252  
                                                                //    253  
                                                                //    254  
                                                                //    255     New Lines (2)
_imp_NEWLINES(2);
                                                                //    256  
                                                                //    257     Print String ("Test the Modulus Operator");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test the Modulus Operator"));
_imp_NEWLINE();
                                                                //    258     Print String ("-------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("-------------------------"));
_imp_NEWLINE();
                                                                //    259     
                                                                //    260     K = 0
K = 0;
                                                                //    261     X = -3       { X is an integer
X = (-3);
                                                                //    262     P = 3
P = 3;
                                                                //    263  
                                                                //    264     J = |-3|
J = _imp_IMOD((-3));
                                                                //    265     Q = |3|
Q = _imp_IMOD(3);
                                                                //    266     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0046;
PASS();
goto L_0047;
L_0046:;
FAIL();
L_0047:;
                                                                //    267     %if Q = 3 %then pass %else fail
if (((Q) != (3))) goto L_0048;
PASS();
goto L_0049;
L_0048:;
FAIL();
L_0049:;
                                                                //    268     
                                                                //    269     J = |CInt4|
J = _imp_IMOD(3);
                                                                //    270     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_004a;
PASS();
goto L_004b;
L_004a:;
FAIL();
L_004b:;
                                                                //    271  
                                                                //    272     J = |K|
J = _imp_IMOD(K);
                                                                //    273     %if J = 0 %then pass %else fail
if (((J) != (0))) goto L_004c;
PASS();
goto L_004d;
L_004c:;
FAIL();
L_004d:;
                                                                //    274  
                                                                //    275     J = |X|
J = _imp_IMOD(X);
                                                                //    276     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_004e;
PASS();
goto L_004f;
L_004e:;
FAIL();
L_004f:;
                                                                //    277  
                                                                //    278     J = |P|
J = _imp_IMOD(P);
                                                                //    279     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0050;
PASS();
goto L_0051;
L_0050:;
FAIL();
L_0051:;
                                                                //    280  
                                                                //    281     P = |P|
P = _imp_IMOD(P);
                                                                //    282     %if P = 3 %then pass %else fail
if (((P) != (3))) goto L_0052;
PASS();
goto L_0053;
L_0052:;
FAIL();
L_0053:;
                                                                //    283  
                                                                //    284     J = |F|
J = _imp_IMOD(F());
                                                                //    285     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0054;
PASS();
goto L_0055;
L_0054:;
FAIL();
L_0055:;
                                                                //    286  
                                                                //    287     J = |(|X|)|
J = _imp_MOD(_imp_IMOD(X));
                                                                //    288     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0056;
PASS();
goto L_0057;
L_0056:;
FAIL();
L_0057:;
                                                                //    289  
                                                                //    290     J = |(-P) + K - (|F * X|)|
J = _imp_MOD(((((((-(P))) + (K)))) - (_imp_IMOD((((int)(F())) * (X))))));
                                                                //    291     %if J = 12 %then pass %else fail
if (((J) != (12))) goto L_0058;
PASS();
goto L_0059;
L_0058:;
FAIL();
L_0059:;
                                                                //    292  
                                                                //    293  
                                                                //    294  select output(1)
_imp_SELECTOUTPUT(1);
                                                                //    295  write(failures,1);  printstring(" failure(s)");  newline
_imp_WRITE(FAILURES, 1);
_imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
_imp_NEWLINE();
                                                                //    296  
                                                                //    297  %End %of %Program
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
// End of file
