Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module matrix_multiplier
- (input wire clk,
- input wire rst,
- input wire [15:0] matrix_A [0:3][0:3],
- input wire [15:0] matrix_B [0:3][0:3],
- output wire [15:0] matrix_C [0:3][0:3]);
- reg [15:0] temp_result [0:3][0:3];
- reg [15:0] matrix_C [0:3][0:3];
- integer i, j, k;
- always @(posedge clk) begin
- if (rst) begin
- for (i = 0; i < 4; i = i + 1) begin
- for (j = 0; j < 4; j = j + 1) begin
- temp_result[i][j] <= 16'h0;
- matrix_C[i][j] <= 16'h0;
- end
- end
- end
- else begin
- if (i < 4) begin
- if (j < 4) begin
- temp_result[i][j] <= 16'h0;
- for (k = 0; k < 4; k = k + 1) begin
- temp_result[i][j] <= temp_result[i][j] + matrix_A[i][k] * matrix_B[k][j];
- end
- j <= j + 1;
- end else begin
- j <= 0;
- i <= i + 1;
- end
- end else begin
- for (i = 0; i < 4; i = i + 1) begin
- for (j = 0; j < 4; j = j + 1) begin
- matrix_C[i][j] <= temp_result[i][j];
- end
- end
- end
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement