/* * b16 core: 16 bits, * inspired by c18 core from Chuck Moore * * Instruction set: * 1, 5, 5, 5 bits * 0 1 2 3 4 5 6 7 * 0: nop call jmp ret jz jnz jc jnc * /3 exec goto ret gz gnz gc gnc * 8: xor com and or + +c *+ /- * 10: A!+ A@+ R@+ lit Ac!+ Ac@+ Rc@+ litc * /1 A! A@ R@ lit Ac! Ac@ Rc@ litc * 18: nip drop over dup >r >a r> a */ `define L [l-1:0] `define DROP { sp, T, N } <= { spinc, N, toN } `timescale 1ns / 1ns module alu(res, carry, zero, T, N, c, inst); parameter l=16; input `L T, N; input c; input [2:0] inst; output `L res; output carry, zero; wire prop, andor, selr; assign #1 { prop, andor, selr } = inst; wire `L sum, logic; wire cout; assign { cout, sum } = T + N + ((c | andor) & selr); assign logic = andor ? (selr ? (T | N) : (T & N)) : T ^ N; assign { carry, res } = prop ? { cout, sum } : { c, logic }; assign zero = ~|T; endmodule // alu module stack(clk, sp, spdec, push, in, out); parameter dep=3, l=16; input clk, push; input [dep-1:0] sp, spdec; input `L in; output `L out; reg `L stackmem[0:(1<