3 == Ports ===========================================================
10 == Constants ========================================================
11 ADD: add the two arguments; treat link as carry
12 SUB: subtract the two arguments; treat link as carry
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
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();
29 case 0: box_out.addDataFromShip(a+b); // ADD
31 case 1: box_out.addDataFromShip(a-b); // SUB
33 case 2: box_out.addDataFromShip(a*b); // MUL
35 case 3: box_out.addDataFromShip(a/b); // DIV
37 case 4: box_out.addDataFromShip(a%b); // REM
39 default: box_out.addDataFromShip(0);
45 == ArchSim ==============================================================
47 == FPGA ==============================================================
54 out_r_, out_a, out_d_);
57 `input(a_r, a_a, a_a_, [(`DATAWIDTH-1):0], a_d)
58 `input(b_r, b_a, b_a_, [(`DATAWIDTH-1):0], b_d)
59 `input(op_r, op_a, op_a_, [(`DATAWIDTH-1):0], op_d)
60 `output(out_r, out_r_, out_a, [(`DATAWIDTH-1):0], out_d_)
61 `defreg(out_d_, [(`DATAWIDTH-1):0], out_d)
64 reg [(`DATAWIDTH-1):0] reg_a;
66 reg [(`DATAWIDTH-1):0] reg_b;
68 reg [(`DATAWIDTH-1):0] reg_op;
70 always @(posedge clk) begin
72 `onread(a_r, a_a) have_a = 1; reg_a = a_d; end
75 `onread(b_r, b_a) have_b = 1; reg_b = b_d; end
78 `onread(op_r, op_a) have_op = 1; reg_op = op_d; end
81 if (have_a && have_b && have_op) begin
83 0: out_d = reg_a + reg_b;
84 1: out_d = reg_a - reg_b;
85 //2: out_d = reg_a * reg_b; // will not synthesize --AM
86 //3: out_d = reg_a / reg_b; // will not synthesize --AM
87 //4: out_d = reg_a % reg_b; // will not synthesize --AM
90 `onwrite(out_r, out_a)
102 == Contributors =========================================================
103 Adam Megacz <megacz@cs.berkeley.edu>