Skip to content

Commit

Permalink
🎨 Formatted Code (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedSobhy01 authored Apr 21, 2024
1 parent b873217 commit 959d8c3
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 281 deletions.
84 changes: 69 additions & 15 deletions Binary2BCD.v
Original file line number Diff line number Diff line change
@@ -1,26 +1,80 @@

module CondAdd3(input[3:0]in,output[3:0]out);

assign out = in >= 5 ? in + 3 : in;
module CondAdd3(in, out);
input [3:0] in;
output [3:0] out;

assign out = in >= 5 ? in + 3:in;
endmodule



module Binary2BCD(in , out);
module Binary2BCD(in, out);
input [7:0] in;
output [11:0] out;
wire [28 : 1] temp;
wire [28:1] temp;

CondAdd3 c1({0,in[7:5]}, temp[4:1]);
CondAdd3 c2({temp[3:1], in[4]}, temp[8:5]);
CondAdd3 c3({temp[7:5], in[3]}, temp[12:9]);
CondAdd3 c4({temp[11:9], in[2]}, temp[16:13]);
CondAdd3 c5({temp[15:13], in[1]}, temp[20:17]);
CondAdd3 c6({0, temp[4], temp[8], temp[12]}, temp[24:21]);
CondAdd3 c7({temp[23:21], temp[16]}, temp[28:25]);

assign out = {0, 0, temp[24], temp[28:25], temp[20:17], in[0]};
endmodule

CondAdd3 c1( {0,in[7:5]}, temp[4 : 1] );
CondAdd3 c2( {temp[3:1] , in[4]}, temp[8 : 5] );
CondAdd3 c3( {temp[7:5] , in[3]}, temp[12 : 9] );
CondAdd3 c4( {temp[11:9] , in[2]}, temp[16 : 13] );
CondAdd3 c5( {temp[15:13] , in[1]}, temp[20 : 17] );
CondAdd3 c6( {0 , temp[4] , temp[8] , temp[12] }, temp[24 : 21] );
CondAdd3 c7( {temp[23:21] , temp[16] }, temp[28 : 25] );
module Binary2BCD_DUT();
reg [7:0] in;
wire [11:0] out;

assign out = { 0 , 0 , temp[24] , temp[28:25] , temp[20:17] , in[0]};
Binary2BCD b2b(in, out);

initial begin
in = 1;
#10;
in = 112;
#10;
in = 251;
#10;
in = 0;
#10;
in = 156;
#10;
in = 045;
#10;
in = 255;
#10;
in = 100;
#10;
in = 124;
#10;
in = 235;
#10;
in = 050;
end

initial begin
$display("Binary2BCD_DUT");
$display("==================================");
$monitor("Expected: 000000000001, Actual: %h\n",out);
#10;
$monitor("Expected: 000000011100, Actual: %h\n",out);
#10;
$monitor("Expected: 000010010011, Actual: %h\n",out);
#10;
$monitor("Expected: 000000000000, Actual: %h\n",out);
#10;
$monitor("Expected: 000000010110, Actual: %h\n",out);
#10;
$monitor("Expected: 000000010101, Actual: %h\n",out);
#10;
$monitor("Expected: 000000111111, Actual: %h\n",out);
#10;
$monitor("Expected: 000000011001, Actual: %h\n",out);
#10;
$monitor("Expected: 000000011100, Actual: %h\n",out);
#10;
$monitor("Expected: 000000111011, Actual: %h\n",out);
#10;
$monitor("Expected: 000000010010, Actual: %h\n",out);
end
endmodule
48 changes: 0 additions & 48 deletions Binary2BCD_tb.v

This file was deleted.

11 changes: 7 additions & 4 deletions DisplayDecoder.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module DisplayDecoder(in,display7);
input [3:0]in;
output [6:0]display7;
module DisplayDecoder(in, out);
input [3:0] in;
output [6:0] out;

reg [6:0] display7;

assign out = display7;

always @(in)
case(in)
Expand All @@ -16,5 +20,4 @@ module DisplayDecoder(in,display7);
9 : display7 = 7'b0000100;
default : display7 = 7'b1111111;
endcase

endmodule
45 changes: 34 additions & 11 deletions InvMixColumns.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module InvMixColumns (stateIn,stateOut);
input[127:0] stateIn;
output[127:0] stateOut;
module InvMixColumns(stateIn, stateOut);
input [127:0] stateIn;
output [127:0] stateOut;

//mul2 function that multiply x by 2^n and fixes the overflow
function [7:0] mul2(input [7:0]in,input integer n);
// Function to multiply by 2 and fix the overflow
function [7:0] mul2(input [7:0] in, input integer n);
integer i;
begin
for(i = 0; i < n; i = i + 1)begin
Expand All @@ -14,28 +14,28 @@ module InvMixColumns (stateIn,stateOut);
end
endfunction

function [7:0] mb0e; //Multiply by 0e
function [7:0] mb0e; // Multiply by 0e
input [7:0] x;
begin
mb0e = mul2(x,3) ^ mul2(x,2)^ mul2(x,1);
end
endfunction

function [7:0] mb0d; //Multiply by 0d
function [7:0] mb0d; // Multiply by 0d
input [7:0] x;
begin
mb0d = mul2(x,3) ^ mul2(x,2) ^ x;
end
endfunction

function [7:0] mb0b; //Multiply by 0b
function [7:0] mb0b; // Multiply by 0b
input [7:0] x;
begin
mb0b = mul2(x,3) ^ mul2(x,1) ^ x;
end
endfunction

function [7:0] mb09; //Multiply by 09
function [7:0] mb09; // Multiply by 09
input [7:0] x;
begin
mb09 = mul2(x,3) ^ x;
Expand All @@ -44,7 +44,7 @@ module InvMixColumns (stateIn,stateOut);

genvar i;
generate
for(i = 0; i < 4; i = i + 1)begin: InvMixColumnsLoop
for(i = 0; i < 4; i = i + 1) begin: InvMixColumnsLoop
//state[0,c] = 0e*state[0,c] + 0b*state[1,c] + 0d*state[2,c] + 09*state[3,c]
assign stateOut[32*i+24+:8] = mb0e(stateIn[32*i+24+:8]) ^ mb0b(stateIn[32*i+16+:8]) ^ mb0d(stateIn[32*i+8 +:8]) ^ mb09(stateIn[32*i +:8]);

Expand All @@ -58,6 +58,29 @@ module InvMixColumns (stateIn,stateOut);
assign stateOut[32*i +:8] = mb0e(stateIn[32*i +:8]) ^ mb0b(stateIn[32*i+24+:8]) ^ mb0d(stateIn[32*i+16+:8]) ^ mb09(stateIn[32*i+8 +:8]);
end
endgenerate
endmodule

module InvMixColumns_DUT();
reg [127:0] stateIn;
wire [127:0] stateOut;

endmodule
InvMixColumns imc(stateIn, stateOut);

initial begin
stateIn = 128'hbd6e7c3df2b5779e0b61216e8b10b689;
#10
stateIn = 128'hfde3bad205e5d0d73547964ef1fe37f1;
#10
stateIn = 128'hd1876c0f79c4300ab45594add66ff41f;
end

initial begin
$display("InvMixColumns_DUT");
$display("==================================");
$monitor("Expected: 4773b91ff72f354361cb018ea1e6cf2c, Actual: %h\n", stateOut);
#10
$monitor("Expected: 2d7e86a339d9393ee6570a1101904e16, Actual: %h\n", stateOut);
#10
$monitor("Expected: 39daee38f4f1a82aaf432410c36d45b9, Actual: %h\n", stateOut);
end
endmodule
21 changes: 0 additions & 21 deletions InvMixColumns_tb.v

This file was deleted.

53 changes: 0 additions & 53 deletions InvShiftRows .v

This file was deleted.

Loading

0 comments on commit 959d8c3

Please sign in to comment.