add more ship files
[fleet.git] / ships / Alu2.ship
1 ship: Alu2
2
3 == Ports ===========================================================
4 data  in:   a
5 data  in:   b
6 data  in:   op
7
8 data  out:  out
9
10 == Constants ========================================================
11 ADD: add the two arguments; treat link as carry
12 SUB: subtract the two arguments; treat link as carry
13
14 == TeX ==============================================================
15 This ship is a two-input arithmetic unit.  It features several
16 opcodes, such as {\tt ADD} and {\tt SUB}.  In my opinion, it is
17 niftycool.
18
19 == Fleeterpreter ====================================================
20 public void service() {
21   if (box_a.dataReadyForShip() &&
22       box_b.dataReadyForShip() &&
23       box_op.dataReadyForShip() &&
24       box_out.readyForItemFromShip()) {
25       int a      = box_a.removeDataForShip();
26       int b      = box_b.removeDataForShip();
27       int op     = box_op.removeDataForShip();
28       switch(op) {
29           case 0: box_out.addDataFromShip(a+b); // ADD
30               break;
31           case 1: box_out.addDataFromShip(a-b); // SUB
32               break;
33           case 2: box_out.addDataFromShip(a*b); // MUL
34               break;
35           case 3: box_out.addDataFromShip(a/b); // DIV
36               break;
37           case 4: box_out.addDataFromShip(a%b); // REM
38               break;
39           default: box_out.addDataFromShip(0);
40               break;
41       }
42   }
43 }
44
45 == ArchSim ==============================================================
46
47 == FPGA ==============================================================
48
49 == Contributors =========================================================
50 Adam Megacz <megacz@cs.berkeley.edu>