Intermediate Code Engine - ICE


ICE Publication

ICE Engine

Download ICE Engine (ICE.zip)

Description of ICE:

Instructions Set & Usage

Syntax Requirements

Instructions & Addressing Mode

Instructions Explained

Example Program (with embedded Instructions)

Example Program( as the actual file )

ICE - Instruction Set & Usage 

All instructions are of the form:

Seq  OPCODE   operand1,   operand2,  operand3

Requirements for the instruction syntax:                     Top

1. A space between seq and opcode is mandatory.
2. A space between the opcode and first operand is mandatory.
3. Any other spaces will be ignored.
4. The operands must be separated by commas.
5. Even if no operands are present, every instruction must include the two commas.

Seq is a mandatory instruction sequence number.
It has the form: numberString

The operands are of the form: [#]digitString

The opcode is a literal string from the following (may be upper or lower case or mixed):


All operands are assumed to be addresses or literals that will have been resolved by a parser, or manually by a programmer. Destinations of jump instructions are the actual instruction number of the instruction to jump to. This is not the memory (byte) address of the instruction. The parser only needs to keep track of the instruction number and attach it to the instruction as the "seq" field.

All data memory addresses are assumed to be the word address (address of an integer, not a byte address).

Instructions and their addressing modes                     Top

I = immediate data, d = direct address

Opcode
operand1
operand2
operand3
      NOP 
      null 
      null 
      null 
      Add 
      I/d 
      I/d 
      d 
      SUB 
      I/d 
      I/d 
      d 
      MUL 
      I/d 
      I/d 
      d 
      DIV 
      I/d 
      I/d 
      d 
      MOD 
      I/d 
      I/d 
      d 
      INC 
      I 
      null 
      d 
      DEC 
      I 
      null 
      d 
      STO 
      I/d 
      null 
      d 
      JMP 
      null 
      null 
      I 
      JEQ 
      I/d 
      I/d 
      I 
      JNE 
      I/d 
      I/d 
      I 
      JLT 
      I/d 
      I/d 
      I 
      JLE 
      I/d 
      I/d 
      I 
      JGT 
      I/d 
      I/d 
      I 
      JGE 
      I/d 
      I/d 
      I 
      SYS 
      I 
      I/d 
      I/d 
      AND 
      I/d 
      I/d 
      d 
      OR 
      I/d 
      I/d 
      d 
      XOR 
      I/d 
      I/d 
      d 
      NOT 
      null 
      null 
      d 
      NEG 
      null 
      null 
      d 
      HLT 
      null 
      null 
      null 


Instructions explained.                                Top

I = immediate data, d = direct address

Opcode
  1. NOP   :   null , null , null



  2. ADD    :  op3 = op1 + op2
  3. SUB    :  op3 = op1 - op2
  4. MUL   :  op3 = op1 * op2
  5. DIV     :  op3 = op1 / op2
  6. MOD   :  op3 = op1 % op2


  7. INC     :  i   null   d
  8. DEC     :  i   null   d



  9. STO    :  I/d   null   d



  10. JMP    :  null   null   I      ( unconditional )
  11. JEQ    :  I/d   I/d   I        ( jump if op1 = op2 )
  12. JNE    :  I/d   I/d   I        ( jump if op1 != op2 )
  13. JLT    :  I/d   I/d   I         ( jump if op1 < op2 )
  14. JLE    :  I/d   I/d   I         ( jump if op1 <= op2 )
  15. JGT    :  I/d   I/d   I        ( jump if op1 > op2 )
  16. JGE    :  I/d   I/d   I        ( jump if op1 >= op2 )

  17. SYS    :  I   I/d   I/d


  18. AND    :  I/d   I/d   d       ( op3 = op1 AND op2 )
  19. OR      :  I/d  I/d   d          ( op3 = op1 OR op2 )
  20. XOR    :  I/d   I/d   d        ( op3 = op1 XOR op2 )


  21. NOT   :   I/d   null   d       ( op3 = NOT op1 )
  22. NEG    :  null   null   d      ( op3 = -op1 )
  23. HLT    :  null   null   null      ( HALT PROGRAM EXECUTION. )


Example Program (with embedded Documentation.)                   Top

AN example program (with embedded documentation)

For the following, assume:

  1. x is integer, storage location 0.
  2. y is integer, storage location 1
  3. z is integer, storage location 2
pseudo-language instruction 
location (instruction #)
mini-assembler instruction
write 'x'
0
SYS #-2,#120,
write '?'
1
SYS #-2,#63,
read x
2
SYS #1, ,0
write 'y'
3
SYS #-2,#121,
write '?'
4
SYS #-2,#63,
ready 'y'
5
SYS #1, ,1
write x
6
SYS #-1,0,
write newline
7
SYS #0, ,
write y
8
SYS #-1,1,
write newline
9
SYS #0, ,
write 'z'
10
SYS #-2,#122,
write '='
11
SYS #-2,#61,
z = x + y
12
ADD 0,1,2
write z
13
SYS #-1,2,
write newline
14
SYS #0, ,
z = x - y
15
SUB 0,1,2
write z
16
SYS #-1,2,
write newline
17
SYS #0, ,
z = x * y
18
MUL 0,1,2
write z
19
SYS #-1,2,
write newline
20
SYS #0, ,
z = x / y
21
DIV 0,1,2
write z
22
SYS #-1,2,
write newline
23
SYS #0, ,
z = x % y
24
MOD 0,1,2
write z
25
SYS #-1,2,
write newline
26
SYS #0, ,
if x > y
27
JLE 0,1,#31
    write '1111'
28
SYS -1,#1111,
    write newline
29
SYS #0, ,
 
30
JMP , ,#33
else
   
    write '2222'
31
SYS #-1,#2222,
    write 'newline'
32
SYS #0, ,
endif
   
if x < y
33
JGE 0,1,#37
    write '3333'
34
SYS #-1,#3333,
    write newline
35
SYS #0, ,
 
36
JMP , ,#38
else
   
    write '4444'
37
SYS #-1,#4444,
endif
   
z = x && y
38
AND 0,1,2
write z
39
SYS #-1,2,
z = x | | y
40
OR 0,1,2
write z
41
SYS #-1,2,
z = x xor y
42
XOR 0,1,2
write z
43
SYS #-1,2,
write newline
44
SYS #0, ,
z = !z
45
NOT 2, ,2
write z
46
SYS #-1,2,
write newline
47
SYS #0, ,
inc z
48
INC #1, ,2
write z
49
SYS #-1,2,
write newline
50
SYS #0, ,
dec z
51
DEC #1, ,2,
write z
52
SYS #-1,2,
write newline
53
SYS #0, ,
     
x = y
54
STO #-2, ,0
write x
55
SYS #-1,0,
write newline
56
SYS #0, ,
write y
57
SYS #-1,1,
write newline
58
SYS #0, ,
if x = = y
59
JNE 0,1,#62
    write '5555'
60
SYS #-1,#5555,
    write newline
61
SYS #0, ,
endif
   
if x ! = y
62
JEQ 0,1,#65
    write '6666'
63
SYS -1,#6666,
    write newline
64
SYS #0, ,
endif
   
if x > = y
65
JLT 0,1,#68
    write '7777'
66
SYS -1,#7777,
    write newline
67
SYS #0, ,
endif
   
if x < = y
68
JGT 0,1,#71
    write '8888'
69
SYS -1,#8888,
    write newline
70
SYS #0, ,
endif
   
write x
71
SYS #-1,0,
write newline
72
SYS #0, ,
x = -x
73
NEG , ,0
write newline
74
SYS #0, ,
nop
75
NOP , ,
halt
76
HLT , ,

Example Program (as the file really appears)                      Top

0   sys  #-2 ,#120 ,
1   sys  #-2 ,#63 ,
2   sys  #1 , ,0
3   sys  #-2 ,#121,
4   sys  #-2 ,#63,
5   sys  #1 , ,1
6   sys  #-1 ,0 ,
7   sys  #0, ,
8   sys  #-1 ,1 ,
9   sys  #0, ,
10   sys  #-2 ,#122 ,
11   sys  #-2 ,#61 ,
12   add  0 ,1 ,2
13   sys  #-1 ,2 ,
14   sys  #0 , ,
15   sub  0 ,1 ,2
16   sys  #-1 ,2 ,
17   sys  #0 , ,
18   mul  0 ,1 ,2
19   sys  #-1 ,2 ,
20   sys  #0 , ,
21   div  0 ,1 ,2
22   sys  #-1 ,2 ,
23   sys  #0 , ,
24   mod  0 ,1 ,2
25   sys  #-1 ,2 ,
26   sys  #0 , ,
27   JLE  0 ,1 ,#31
28   sys  -1 ,#1111 ,
29   sys  #0 , ,
30   JMP  , ,#33
31   sys  #-1 ,#2222 ,
32   sys  #0 , ,
33   JGE  0 ,1 ,#37
34   sys  #-1 ,#3333 ,
35   sys  #0, ,
36   JMP  , ,#38
37   sys  #-1 ,#4444 ,
38   and  0 ,1 ,2
39   sys  #-1 ,2 ,
40   or  0 ,1 ,2
41   sys  #-1 ,2 ,
42   xor  0 ,1 ,2
43   sys  #-1 ,2 ,
44   sys  #0 , ,
45   not  2 , ,2
46   sys  #-1 ,2 ,
47   sys  #0 , ,
48   inc  #1 , ,2
49   sys  #-1 ,2 ,
50   sys  #0 , ,
51   dec  #1 , ,2
52   sys  #-1 ,2 ,
53   sys  #0 , ,
54   sto  2, ,0
55   sys  #-1 ,0 ,
56   sys  #0 , ,
57   sys  #-1 ,1 ,
58   sys  #0 , ,
59   jne  0 ,1 ,#62
60   sys  #-1 ,#5555 ,
61   sys  #0 , ,
62   jeq  0 ,1 ,#65
63   sys  -1 ,#6666 ,
64   sys  #0 , ,
65   jlt  0 ,1 ,#68
66   sys  -1 ,#7777 ,
67   sys  #0 , ,
68   jgt  0 ,1 ,#71
69   sys  -1,#8888 ,
70   sys  #0 , ,
71   sys  #–1 ,0 ,
72   sys  #0 , ,
73   neg  , ,0
74   sys  #0 , ,
75   nop  , ,
76   hlt  , ,


if you have any questions please mail me at:Mohsen Chitsaz