Project 4 – Two Dimensional Arrays

advertisement
Project 4 – Two Dimensional Arrays
ECE 122 Spring 2008
The use of memory, whether it is RAM, ROM, SRAM or any of the other many types, plays an essential role in
modern computing and electronics. In this project you will investigate the functionality of RAM and how individual
memory locations are selected for read and write operations.
A common method used to select different memory locations is to use a decoder. The binary address of the
desired memory location is input to the decoder and the decoder activates the line of the memory location to be
manipulated. This technique works fine for memory with only a few locations, yet becomes cumbersome as increasing
storage space is required. For example, to access a 256
word memory, an 8 X 256 decoder housing 256 “and” gates would be required. It is
evident that as memory gets larger, using a decoder to select locations not only requires
many components but takes up precious space as well. To solve this problem coincident
decoding is used.
As shown in the diagram to the right, coincident decoding involves orienting two
decoders such that their output lines intersect to form a grid of memory
locations that can be selected. One address input selects the column of the memory
location and the other selects the row. Therefore a 256 word memory only requires two
4 X 16 decoders housing 32 total “and” gates, a substantial improvement.
For this project you will design a program that operates much like a 256 word RAM where coincident decoding
is used. Given a binary address, your program will be able to select the requested location in memory and perform read
and write operations making semi-permanent changes to the memory. Print out diagrams of the hypothetical 256 word
RAM to show various manipulations to its contents. The following paragraphs will provide all the necessary
information to write a Java program that performs as described:
Part 1 – The Memory:
When using coincident decoding, the memory locations form a grid with the dimensions of the number of
decoder outputs. In Java this grid can be represented by a two-dimensional array. Create a two-dimensional array that
holds 256 integer values; look to the decoders for the dimensions. Suppose that all we know about the data stored in
the memory is that each location holds a random value between zero and ten. In other words, use the Random class to
initialize the array elements to a value between zero and ten. (Please note: In actual RAM the memory locations store
binary numbers, not integers.)
Part 2 – The Decoders:
The next task is to design a piece of code that functions like a decoder. When the user enters two four bit binary
addresses to select the row and column of memory, your program should be able to convert them to decimal and select
the appropriate array element. You may find this part a little tricky. It is advisable to create a method that accepts a
binary number, converts it to decimal, and returns the decimal value. This way you can send the desired row/column
address from the user (in binary) to this method and it will return a decimal value that can be used to select a
row/column in the two dimensional array.
Part 3 –A Diagram:
At this point your program should be able to accept two binary address lines and pick out the corresponding
array element that holds a random value between zero and ten. Now write a method that prints out a hypothetical
diagram of the 256 word RAM that shows the element in memory that has been selected. The row and column number
as well as the value stored in the selected array element should be printed above the diagram. For example, the output
for a four by four array may look as follows:
The value stored in row 2 and column 3 is 4.
It is located in the diagram at X.
0 0 0 0
0 0 0 0
0 0 0 X
0 0 0 0
Note: For the sixteen by sixteen array used for the 256 word RAM, the row and column numbers should range from
zero to fifteen.
Part 4 – Memory Operations:
You have now created a fully functional 256 word RAM. Nice work! Although the diagram plays no part in the
functionality of the RAM, it serves as a nice way to ensure your program is working properly. In Part 3 you have
shown your program’s ability to read from a specific location and the write function of RAM could easily be
accomplished using an assignment statement.
Next you will manipulate data stored in the memory locations of your 256 word RAM. Some of these
operations will require you to write new methods, however, they will be very similar to those previously written.
a.) Input row location 1011 and column location 0010 to your program and call the method from Part 3.
b.) Print out a diagram similar to that in Part 3 with all locations that hold the same value as row 1011 and
column 0010 marked with an X. Below the diagram also print how many times the value is found in memory.
This part will require writing a new method.
c.) Replace all memory locations that hold the same value as row 1011 and column 0010 with the value –1. The
value held in row 1011 and column 0010 should remain unchanged. This part will require writing a new
method.
d.) Lastly call the method created in part b that prints out all locations that hold the same value as row 1011 and
column 0010. If the method in part c worked properly, an X should appear only in row eleven and column two,
the original location (recall row and column numbers range from zero to fifteen).
Download