2023-02-13 16:49:17 +00:00
|
|
|
/* alu.v - implementation of the ALU of the 9086 CPU
|
|
|
|
|
|
|
|
This file is part of the 9086 project.
|
|
|
|
|
|
|
|
Copyright (c) 2023 Efthymios Kritikos
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
2023-02-11 14:43:53 +00:00
|
|
|
`include "alu_header.v"
|
2023-02-09 20:16:50 +00:00
|
|
|
|
2023-02-12 01:05:39 +00:00
|
|
|
module ALU(input [15:0]A,input [15:0]B, input oe,output reg [15:0]OUT,input [`ALU_OP_BITS-1:0]op,output wire [7:0]FLAGS,input Wbit);
|
2023-02-11 14:43:53 +00:00
|
|
|
reg C_FLAG;
|
|
|
|
|
2023-02-12 01:05:39 +00:00
|
|
|
assign FLAGS={(Wbit==1)?OUT[15:15]:OUT[7:7],(Wbit==1) ? (OUT[15:0]=='h0000) : (OUT[7:0]=='h00),5'b00000,C_FLAG};
|
|
|
|
|
2023-02-11 14:43:53 +00:00
|
|
|
always @ ( * ) begin
|
2023-02-12 01:28:37 +00:00
|
|
|
if(Wbit==1)begin
|
|
|
|
case (op)
|
|
|
|
`ALU_OP_ADD: {C_FLAG,OUT}=A+B;
|
|
|
|
`ALU_OP_SUB: {C_FLAG,OUT}=A-B;
|
|
|
|
`ALU_OP_AND: OUT=A&B;
|
|
|
|
`ALU_OP_OR: OUT=A|B;
|
|
|
|
`ALU_OP_XOR: OUT=A^B;
|
|
|
|
endcase
|
|
|
|
end else begin
|
|
|
|
case (op)
|
|
|
|
`ALU_OP_ADD: {C_FLAG,OUT[7:0]}=A[7:0]+B[7:0];
|
|
|
|
`ALU_OP_SUB: {C_FLAG,OUT[7:0]}=A[7:0]-B[7:0];
|
|
|
|
`ALU_OP_AND: OUT=A&B;
|
|
|
|
`ALU_OP_OR: OUT=A|B;
|
|
|
|
`ALU_OP_XOR: OUT=A^B;
|
|
|
|
endcase
|
|
|
|
end
|
2023-02-11 14:43:53 +00:00
|
|
|
end
|
2023-02-09 20:16:50 +00:00
|
|
|
|
|
|
|
endmodule
|