Advanced Computer Architechture Lab Assignment 3
Advanced Computer Architechture Lab Assignment 3
Advanced Computer Architechture Lab Assignment 3
Block Diagram:
Verilog Module:
Verilog Code:
SUB: begin
Result = Operand1 - Operand2;
flagC = Result[8];
flagZ = (Result == 16'b0);
end
MUL: begin
Result = Operand1 * Operand2;
flagZ = (Result == 16'b0);
end
AND: begin
Result = Operand1 & Operand2;
flagZ = (Result == 16'b0);
end
OR: begin
Result = Operand1 | Operand2;
flagZ = (Result == 16'b0);
end
NAND: begin
Result = ~(Operand1 & Operand2);
flagZ = (Result == 16'b0);
end
NOR: begin
Result = ~(Operand1 | Operand2);
flagZ = (Result == 16'b0);
end
XOR: begin
Result = Operand1 ^ Operand2;
flagZ = (Result == 16'b0);
end
default: begin
Result = 16'b0;
flagC = 1'b0;
flagZ = 1'b0;
end
endcase
end
endmodule
Truth Table:
Block Diagram:
Verilog Code:
module main_module(y1,y2,y3,cout,carry_out,m,sel,a,b,x,y,A,B,j,k,cin,Op);
wire [15:0]s;
wire [15:0]sum;
wire [15:0]buff1;
wire [15:0]buff2;
wire [15:0]rightshift;
wire [15:0]leftshift;
CLAdder c1(s,cout,a,b,cin);
subtractor sub1(sum,carry_out,m,x,y,Op);
multiplier m1(buff1,buff2,A,B);
shifter shift1(leftshift,rightshift,j,k);
always@*
begin
if(sel==2'b00)
begin
y1[15:0] = s[15:0];
y2[31:0] = 31'bz;
y3[15:0] = 16'bz;
end
else if(sel==2'b01)
begin
y1[15:0] = sum[15:0];
y2 [15:0] = 16'bz;
y3[15:0] = 16'bz;
end
else if(sel==2'b10)
begin
y2[31:0] = {buff1[15:0],buff2[15:0]};
y1[15:0] = 16'bz;
y3[15:0] = 16'bz;
end
else if(sel==2'b11)
begin
y3[15:0] = leftshift[15:0];
y1[15:0] = rightshift[15:0];
y2 [15:0] = 16'bz;
end
end
endmodule
wire C0,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15;
wire B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,B12,B13,B14,B15;
module multiplier(buff1,buff2,A,B);
output [15:0]buff1;
output [15:0]buff2;
input [15:0]A;
input [15:0]B;
reg [15:0]buff1;
reg [15:0]buff2;
wire [15:0]A;
wire [15:0]B;
reg B0;
reg [15:0]C;
integer i;
always@*
begin
buff1 = 0;
C[15:0] = B[15:0];
for(i=0;i<16;i=i+1)
begin
B0 = C[0];
if(B0==1)
begin
buff1[15:0] = buff1 [15:0]+ A[15:0];
C = C >> 1;
C[15] = buff1[0];
buff1 = buff1 >> 1;
end
else if(B0==0)
begin
C = C >> 1;
C[15] = buff1[0];
buff1 = buff1 >> 1;
end
buff2 = C[15:0];
end
end
endmodule
module shifter(
output reg [15:0] leftshift,
output reg [15:0] rightshift,
input [15:0] j,
input [15:0] k);
always@(k)
begin
leftshift = j<<k;
rightshift <= j>>k;
end
endmodule
Truth Table: