Verilog finishing code

Status
Not open for further replies.

Tigger200

Newbie level 1
Joined
Jan 31, 2017
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
22
I need to fill out these gaps. Can someone help me


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
module block_mul(clk, a,b,start,res,r,finish);
  input [7:0] a,b;
  input start,clk,res;
  output [15:0] r;
  output reg finish;
 
  reg [7:0] regA, regB;
  reg [16:0] regR;
 
  reg [2:0] step;
 
  reg swap_a, swap_b;
  reg shift_r;
 
  wire [ _______________ ] mult_out;
  wire [ _______________ ] add_out;
 
  assign mult_out= regA[3:0]*regB[3:0];
  assign add_out = _______________ + regR[15:8];
  assign r = regR[15:0];
 
  always@(posedge clk) begin
    if(start && step == 0) begin
      regA <= a;
      regB <= b;
      regR <= 0;
    end else begin
      if(swap_a) begin
        regA[7:4] ___________________ regA[3:0];
        regA[3:0] ___________________ regA[7:4];
      end else
        regA <= regA;
 
      if(swap_b) begin
        regB <= { _______________ };
      end else
        regB <= regB;
 
      if(shift_r) begin
    regR[16:13] <= 0;
    regR[12:4]  <= _______________;
        regR[3:0]   <= regR[7:4];
      end else if(step != 0) begin
        regR[16:8]  <= _______________;
    regR[7:0]   <= regR[7:0];
      end else begin
        regR        <= regR;
      end
    end
  end
 
  always@(posedge clk) begin
    if(res) begin
      step   <= 0;
      finish <= 0;
    end else begin
      finish <= 0;
      if(step == 0 && start) begin
        step    <= 1;
    swap_a  <= ___________________;
        swap_b  <= ___________________;
    shift_r <= ___________________;
      end else if(step == 1) begin
    step    <= 2;
        swap_a  <= ___________________;
        swap_b  <= ___________________;
        shift_r <= ___________________;
      end else if(step == 2) begin
    step    <= 3;
        swap_a  <= ___________________;
        swap_b  <= ___________________;
        shift_r <= ___________________;
      end else if(step == 3) begin
    step    <= 4;
        swap_a  <= ___________________;
        swap_b  <= ___________________;
        shift_r <= ___________________;
      end else if(step == 4) begin
    step    <= 0;
        swap_a  <= 0;
        swap_b  <= 0;
        shift_r <= 0;
    finish <= 1;
      end
    end
  end
 
endmodule
 
module test();
  reg[7:0] a,b;
  wire[15:0] result;
  reg clk,res,start;
  wire done;
 
  block_mul dut(clk,a,b,start,res,result,done);
 
  always begin
    clk=0; #5; clk=1; #5;
  end
  initial begin
    $dumpvars(0,dut);
    res=1; #22;
    res=0;
    a=63; b=63; start=1; #10
    start=0; #100
    a=1; b=1; start=1; #10
    start=0; #100
    a=255; b=255; start=1; #10
    start=0; #100
    a=3; b=64; start=1; #10
    start=0; #100
    a=4; b=128; start=1; #10
    start=0; #100
    a=0; b=0;
    $finish;
  end
endmodule

 
Last edited by a moderator:

Nobody is going to do your homework for you.

If you have a specific question then ask that question, instead of asking someone to help you.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…