InstructionMemory.v
5.66 KB
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
module InstructionMemory(address, instruction);
input[31:0] address;
output reg[31:0] instruction;
reg[31:0] instr_mem[127:0];
/*
// Factorial #1
initial begin
instr_mem[0] = 32'b00100000000100000000000000000001; // addi, $0, $s0($16), +1
instr_mem[1] = 32'b00100000000010000000000000001010; // addi, $0, $t0($8), +10
instr_mem[2] = 32'b00100001001010010000000000000001; // addi, $t1($9), $t1($9), +1
instr_mem[3] = 32'b00000010000010010000000000011000; // mult, $s0($16), $t1($9)
instr_mem[4] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[5] = 32'b00010101000010011111111111111100; // bne, $t0($8), $t1($9), -4
instr_mem[6] = 32'b00100010000000100000000000000000; // addi, $s0($16), $v0($2), +0
end
*/
/*
// Factorial #2
initial begin
instr_mem[0] = 32'b00100000000100000000000000000001; // addi, $0, $s0($16), +1
instr_mem[1] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[2] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[3] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[4] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[5] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[6] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[7] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[8] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[9] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[10] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[11] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[12] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[13] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[14] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[15] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[16] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[17] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[18] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[19] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[20] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[21] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[22] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[23] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[24] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[25] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[26] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[27] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[28] = 32'b00100001000010000000000000000001; // addi, $t0($8), $t0($8), +1
instr_mem[29] = 32'b00000010000010000000000000011000; // mult, $s0($16), $t0($8)
instr_mem[30] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[31] = 32'b00100010000000100000000000000000; // addi, $s0($16), $v0($2), +0
end
*/
// No Hazard
initial begin
instr_mem[0] = 32'b00100000000100000000000000000001; // addi, $0, $s0($16), +1
instr_mem[1] = 32'b00100000000010000000000000000001; // addi, $0, $t0($8), +1
instr_mem[2] = 32'b00100000000010010000000000000010; // addi, $0, $t1($9), +2
instr_mem[3] = 32'b00100000000010100000000000000011; // addi, $0, $t2($10), +3
instr_mem[4] = 32'b00100000000010110000000000000100; // addi, $0, $t3($11), +4
instr_mem[5] = 32'b00100000000011000000000000000101; // addi, $0, $t4($12), +5
instr_mem[6] = 32'b00100000000011010000000000000110; // addi, $0, $t5($13), +6
instr_mem[7] = 32'b00000001000010000000000000011000; // mult, $t0($08), $t0($8)
instr_mem[8] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[9] = 32'b00000001000010010000000000011000; // mult, $t0($08), $t1($9)
instr_mem[10] = 32'b00000000000000001000100000010010; // mflo, $s1($17)
instr_mem[11] = 32'b00000001001010010000000000011000; // mult, $t1($9), $t1($9)
instr_mem[12] = 32'b00000000000000001001000000010010; // mflo, $s2($18)
instr_mem[13] = 32'b00000000000000001001100000010010; // mflo, $s3($19)
instr_mem[14] = 32'b00100000000000100000000000011000; // addi, $0, $v0($2), +24
instr_mem[15] = 32'b00100000000100000000000000000001; // addi, $0, $s0($16), +1
instr_mem[16] = 32'b00100000000010000000000000000001; // addi, $0, $t0($8), +1
instr_mem[17] = 32'b00100000000010010000000000000010; // addi, $0, $t1($9), +2
instr_mem[18] = 32'b00100000000010100000000000000011; // addi, $0, $t2($10), +3
instr_mem[19] = 32'b00100000000010110000000000000100; // addi, $0, $t3($11), +4
instr_mem[20] = 32'b00100000000011000000000000000101; // addi, $0, $t4($12), +5
instr_mem[21] = 32'b00100000000011010000000000000110; // addi, $0, $t5($13), +6
instr_mem[22] = 32'b00000001000010000000000000011000; // mult, $t0($08), $t0($8)
instr_mem[23] = 32'b00000000000000001000000000010010; // mflo, $s0($16)
instr_mem[24] = 32'b00000001000010010000000000011000; // mult, $t0($08), $t1($9)
instr_mem[25] = 32'b00000000000000001000100000010010; // mflo, $s1($17)
instr_mem[26] = 32'b00000001001010010000000000011000; // mult, $t1($9), $t1($9)
instr_mem[27] = 32'b00000000000000001001000000010010; // mflo, $s2($18)
instr_mem[28] = 32'b00000000000000001001100000010010; // mflo, $s3($19)
instr_mem[29] = 32'b00100000000000100000000000111000; // addi, $0, $v0($2), +56
end
always @ (*) begin
instruction = instr_mem[address/4];
end
endmodule