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:
Please ensure that your generated MIL code meets the above four 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 a final example, the MIL code for the
MIL code for the fibonacci.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 |
param name | adds the named parameter to the queue of parameters for the next function call |
call name, dest | calls the function with the specified name, storing the result in dest |
ret src | returns from the current function, passing src as the return value. src can be an immediate |
. 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 |
= dst, src | dst = src (src can be an immediate) |
= dst, $0 | dst = $0 ($0 is the 1st function parameter) |
=[] dst, src, index | dst = src[index] (index can be an immediate) |
[]= dst, index, src | dst[index] = src (index and src can be immediates) |
.< 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 |
+ 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 |
<= 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 OR) |
&& dst, src1, src2 | dst = src1 && src2 (logical AND) |
! dst, src | dst = !src (logical NOT) |
: label | declares a label |
:= label | goto label |
?:= label, predicate | if predicate is true (1) goto label |