The MIL Intermediate Code Representation

Your code generator will output "MIL" intermediate code, which can be directly executed by the mil_run MIL interpreter. The MIL interpreter assumes the following about a MIL program:

  1. Each line in the MIL file contains at most one MIL instruction
  2. Each line is at most 254 characters long
  3. All variables are defined before they are used

Please ensure that your generated MIL code meets the above three requirements.

As an example, for the primes.min MINI-L program, the corresponding MIL code might look like this. Note that your generated MIL code may look slightly different. However, your MIL code must behave the same way when it is executed by the mil_run MIL interpreter. As another example, the MIL code for the mytest.min MINI-L program might appear as it does here.

Each instruction in the MIL intermediate code representation is described in detail in the table below.

Syntax Semantics
Variable Declaration Statements
. name declares a name for a scalar variable
.[] name, n declares a name for an array variable consisting of n (must be a positive whole number) elements, with name[0] being the first element
Copy Statements
= dst, src dst = src (src can be an immediate)
Array Access Statements
=[] dst, src, index dst = src[index] (index can be an immediate)
[]= dst, index, src dst[index] = src (index and src can be immediates)
Input/Output Statements
.< dst read a value into dst from standard in
.[]< dst, index read a value into dst[index] from standard in
.> src write the value of src into standard out
.[]> src, index write the value of src[index] into standard out
Arithmetic Operator Statements (one or both source operands can be immediates)
+ dst, src1, src2 dst = src1 + src2
- dst, src1, src2 dst = src1 - src2
* dst, src1, src2 dst = src1 * src2
/ dst, src1, src2 dst = src1 / src2
% dst, src1, src2 dst = src1 % src2
Comparison Operator Statements (one or both source operands can be immediates)
< dst, src1, src2 dst = src1 < src2
<= dst, src1, src2 dst = src1 <= src2
!= dst, src1, src2 dst = src1 != src2
== dst, src1, src2 dst = src1 == src2
>= dst, src1, src2 dst = src1 >= src2
> dst, src1, src2 dst = src1 > src2
Logical Operator Statements (one or both source operands can be immediates)
|| dst, src1, src2 dst = src1 || src2 (logical OR)
&& dst, src1, src2 dst = src1 && src2 (logical AND)
! dst, src dst = !src (logical NOT)
Label Declaration Statements
: label declares a label
Branch Statements
:= label goto label
?:= label, predicate if predicate is true (1) goto label