From ea26b038d9dcf73354b4803e6e2ea91c8267c75f Mon Sep 17 00:00:00 2001 From: uvok Date: Thu, 1 Jan 2026 15:58:45 +0100 Subject: add ALU --- nandgame/alu.sv | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 nandgame/alu.sv diff --git a/nandgame/alu.sv b/nandgame/alu.sv new file mode 100644 index 0000000..0de6546 --- /dev/null +++ b/nandgame/alu.sv @@ -0,0 +1,44 @@ +// nandgame ALU + +`timescale 1us/1us + +`include "nandgame_types.v" +`include "arith_unit.sv" +`include "logic_unit.sv" + +module alu #( + parameter DATA_WIDTH = 16 +) ( + input [(DATA_WIDTH-1):0] X, + input [(DATA_WIDTH-1):0] Y, + input logic u, + input logic [1:0] opcode, + input logic zx, + input logic sw, + + output logic [(DATA_WIDTH-1):0] RES +); + +logic [(DATA_WIDTH-1):0] MyX = zx ? 0 : sw ? Y : X; +logic [(DATA_WIDTH-1):0] MyY = sw ? X : Y; +logic [(DATA_WIDTH-1):0] MyResA; +logic [(DATA_WIDTH-1):0] MyResL; + +arith_unit au ( + .X(MyX), + .Y(MyY), + .RES(MyResA), + .operation(opcode) +); + +logic_unit lu ( + .X(MyX), + .Y(MyY), + .RES(MyResL), + .operation(opcode) +); + +assign RES = u ? MyResL : MyResA; + + +endmodule -- cgit v1.2.3