-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstructionMemory.v
58 lines (48 loc) · 2.05 KB
/
InstructionMemory.v
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
`timescale 1ns / 1ps
////////////////////////////////////////////////////////////////////////////////
// ECE369A - Computer Architecture
// Laboratory 1
// Module - InstructionMemory.v
// Description - 32-Bit wide instruction memory.
//
// INPUT:-
// Address: 32-Bit address input port.
//
// OUTPUT:-
// Instruction: 32-Bit output port.
//
// FUNCTIONALITY:-
// Similar to the DataMemory, this module should also be byte-addressed
// (i.e., ignore bits 0 and 1 of 'Address'). All of the instructions will be
// hard-coded into the instruction memory, so there is no need to write to the
// InstructionMemory. The contents of the InstructionMemory is the machine
// language program to be run on your MIPS processor.
//
//
//we will store the machine code for a code written in C later. for now initialize
//each entry to be its index * 3 (memory[i] = i * 3;)
//all you need to do is give an address as input and read the contents of the
//address on your output port.
//
//Using a 32bit address you will index into the memory, output the contents of that specific
//address. for data memory we are using 1K word of storage space. for the instruction memory
//you may assume smaller size for practical purpose. you can use 128 words as the size and
//hardcode the values. in this case you need 7 bits to index into the memory.
//
//be careful with the least two significant bits of the 32bit address. those help us index
//into one of the 4 bytes in a word. therefore you will need to use bit [8-2] of the input address.
////////////////////////////////////////////////////////////////////////////////
module InstructionMemory(Address, Instruction);
input [31:0] Address; // Input Address
integer i;
output reg [31:0] Instruction; // Instruction at memory location Address
reg [31:0] Memory [0:1024];
initial begin
//$readmemh("private_instruction_memory.txt",Memory);
end
/* Please fill in the implementation here */
always @(Address)begin
Instruction = Memory[Address[31:2]];
//end
end
endmodule