You're seeing this message because you're using an older version of Internet Explorer that is unsupported on our website. Please use these links to upgrade to a modern web browser that fully supports our website and protects your computer from security risks.

Mozilla Firefox

Mozilla Firefox

Google Chrome

Google Chrome

Internet Explorer 8

Hide this message

 
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 numberString is a string of decimal digits that represent a positive integer quantity. This will be used as a possible branch label by the mICE virtual machine.

The operands are of the form: [#]digitString

    The # is optional, it indicates that the operand is immediate data. (i.e. data is stored in the instruction) If the data is directly addressed (i.e. operand is address of data), the # must not appear. Direct addressing is the default.
    The digitString is a string of decimal digits that represent an integer quantity. It may begin with a plus + or minus -.

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

    NOP   ADD   SUB   MUL   DIV   MOD   INC   DEC   STO   JMP   JEQ   
    JNE   JLT   JLE   JGT   JGE   SYS AND OR   XOR   NOT   NEG   HLT   


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


    • no operation is performed. (wait one cycle) Can be useful in constructing branch structures

  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

    • op1 and op2 can be immediate or direct, op3 is destination so it must be an address.

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


    • INC and DEC are useful in loops For inc and dec ,the first operand is an immediate value. (a fixed amount). The third operand (directly addressed), is the memory location to be incremented or decremented.

  9. STO    :  I/d   null   d


    • The data (immediate or directly addressed) from op1 is stored in op3.

  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 )

      For all jump instructions, the third operand is a code address that is stored in the instruction itself. The # is mandatory on op3. The code address is the instruction number, not the memory address of the instruction. For all conditional jumps, op1 and op2 may be direct or immediate.
  17. SYS    :  I   I/d   I/d

    • SYS is a system call. The first operand is a service number. The 2nd and 3rd are data or null. Negative service numbers are used for services that do not return a data value (e.g. write integer is -1). Positive service numbers are used for those that DO return a data value (e.g. read integer is 1). Any returned value is returned into the 3rd operand.

  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 )

    • Logical AND, OR, XOR are similar to arithmetic instructions. Op1 and op2 can be immediate or direct address. Op3 must be an address.

  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  , ,