Advertisement
mayankherode_04

Untitled

Sep 10th, 2023
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module matrix_multiplier
  2. (input wire clk,
  3. input wire rst,
  4. input wire [15:0] matrix_A [0:3][0:3],
  5. input wire [15:0] matrix_B [0:3][0:3],
  6. output wire [15:0] matrix_C [0:3][0:3]);  
  7. reg [15:0] temp_result [0:3][0:3];
  8. reg [15:0] matrix_C [0:3][0:3];
  9.  
  10. integer i, j, k;
  11.  
  12. always @(posedge clk) begin
  13. if (rst) begin
  14. for (i = 0; i < 4; i = i + 1) begin
  15. for (j = 0; j < 4; j = j + 1) begin
  16. temp_result[i][j] <= 16'h0;
  17. matrix_C[i][j] <= 16'h0;
  18. end
  19. end
  20. end
  21. else begin
  22. if (i < 4) begin
  23. if (j < 4) begin
  24. temp_result[i][j] <= 16'h0;
  25. for (k = 0; k < 4; k = k + 1) begin
  26. temp_result[i][j] <= temp_result[i][j] + matrix_A[i][k] * matrix_B[k][j];
  27. end
  28. j <= j + 1;
  29. end else begin
  30. j <= 0;
  31. i <= i + 1;
  32. end
  33. end else begin
  34. for (i = 0; i < 4; i = i + 1) begin
  35. for (j = 0; j < 4; j = j + 1) begin
  36. matrix_C[i][j] <= temp_result[i][j];
  37. end
  38. end
  39. end
  40. end
  41. end
  42. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement