Readings
- Memory:
- N2T: Section 3 Intro, 3.1 (Memories/RAM), 3.2.3, 3.3 (RAM8, n-Register Memory), 3.4, 3.5 (slides 31-46, 52-58, 60-end)
- Assembly Language:
Description
This assignment will focus on the following tasks:
- building the main memory units
- writing programs in Assembly (at the end)
Build the
RAM
circuits described in Project 3:
N2T: Project 3
Chapters 3 provides the contract for each chip, i.e. description of its behavior, names and number inputs, names and state of outputs. The API is available here:
The Hack Chipset
Assembly Language Programming
vvv
vvv Scroll to the bottom. Consider Starting with the Assembly section.
vvv
Design in Logisim
Note the following requirements:
- create empty folder
cs221/04/
and save the Logisim files there
- label the input pins exactly as specified in the contract:
- if there are multiple circuits in the same file, add pin index, i.e. a1, a2, a3
- if a name is rejected, add _pin, i.e. in_pin, out_pin
Here are additional specific requirements:
RAMxx
:
- save in individual files named RAMxx.circ replacing xx accordingly
RAM8
should be built out of 8 Logisim Register
components (under Memory
)
RAMxx
should be built out of RAMyy
, the closest previously built smaller RAM
circuit; use the Logisim RAM
component (under Memory
) and pick the right values under Properites
:
- for example, if you are looking for
RAM128
equivalent adjust the properties so that at the top it says RAM 128 x 16
- hint: how many bit addresses do you need in order to enumerate 128 different cells?
- make sure to set the "Asynchronous read" property to "Yes"; this will ensure that data immediately shows on the output when the address is changed
- make sure to set the "Appearance" property to "Classic Logisim; this will make the chip more compact
- for testing you will need to attach a clock
- minimal use of basic gates
- Test Images: Show evidence of testing for each RAM by saving a screenshot name
RAMxx.png
(replacing xx
accordingly). A single screenshot should show values loaded in all the specified banks/cells below per RAM:
- RAM8
- 1st, 5th, last register with values
AA,BB,CC
respectively
- RAM64, RAM512, RAM4k, RAM16k
- next-to-last bank: 1st, mid, last cell with values
AA,BB,CC
respectively
- last bank: 1st, mid, last cell with values
DD,EE,FF
respectively
- to see last cell in a bank: click on the Hand, click on a cell in the bank, PageDown all the way; the last cell is the one in bottom-right corner
- here 1st cell means, whichever happens to be first so that we can see the last cell; mid cell is the one between 1st and last (integer division)
Splitter
: Logisim has a component called Splitter
under Wiring
; it can be used to select a single bit from a bus (or a group of bits)
Constants
: note that Constants
components can be given width which makes it possible to propagate multiple 1s or 0s on a wide bus
Design in HDL
Note the following additional requirements:
- in folder cs221/04/a/ and cs221/04/b/ copy one at a time the starter code for the required circuits:
- do not copy
Register.hdl
(if you do, testing will be very slow)
Here are additional specific requirements:
RAMxx
:
RAM8
should be built out of 8 Register
chips
RAMxx
should be built out of RAMyy
, the closest previously built smaller RAM
chip
- minimal use of basic gates
Splitter
: to achieve the effect of splitting wires in HDL you write gatepin=wire[i..j]
or gatepin[i..j]=wire
(the widths have to match)
more generally, you can write gatepin[i..j]=wire[p..q]
(the widths have to match), but this general version will not be needed for this assignment
gatepin
could be an input or output pin of the gate
Constants
: to achieve the effect of sending the constant values 1 or 0 to a pin in HDL you write gatepin=true
or gatepin=false
(should work regardless of pin width)
Modify and test the respective .hdl file given by the authors:
- Win users: could use Notepad (shows line numbers at bottom right)
- Mac users: could use TextEdit; ensure file is edited and saved in Plain Text: "Format Menu:Make Plain Text"
Assembly Language Programming
If you have implemented Bubble Sort previously, do not refer to your previous work.
Implement the
Bubble Sort algorithm. Briefly the algorithm works as follows:
1. Go through the whole array examining each pair of items. Exchange the items in a pair if the first is bigger than the second.
2. Repeat Step 1. n-1
times, where n
is the size of the array.
// does one run of the bubble sort algorithm -- every
// pair of neighbors that are out of order are swapped
void bubbleRun(int[] numbers)
{
for (int i = 0; i < numbers.length-1; i = i + 1)
{
if (numbers[i] > numbers[i+1]) // if out of order:
{
int temp = numbers[i]; // swap them
numbers[i] = numbers[i+1];
numbers[i+1] = temp;
}
}
}
// sorts an array in increasing order -- simply executes *n-1*
// bubble runs through the array, where *n* is the array length
void bubbleSort(int[] numbers)
{
int n = numbers.length;
for (int run = 1; run <= n-1; run = run + 1)
{
bubbleRun(numbers);
}
}
Wikipedia provides and excellent visualization of the process:
Hint: Instead of
size you might find it more convenient to have a variable that represents
number of pairs. In either case, it should be adjusted for
cell size=4.
Hint: In general, the meaning of a comparison should be flipped from what it would be in CS111.
Hint: An
if
statement is just like a loop. It still has a
jump/branch
to skip over a section of code that should not be done.
Part I
In file
bubbleRunSimple.asm write a program that only implements Step 1. of
Bubble Sort. Create an array of 6 elements at the top and check if the array was modified correctly.
To view the contents of the main memory, at the top select
"Tools:=View memory contents"
. This will show the section of main memory where the array is located. It may be good to select
Dec
at the bottom to see the decimal versions of the cells.
As you step through the code both the register and main memory will update and you can check if the code behaves as expected.
Make sure to test with:
scrambled array,
sorted array,
reverse sorted array.
Part II
In file
bubbleSortSimple.asm copy the contents of
bubbleRunSimple.asm and make the following changes.
Wrap the copied code in another loop so that
bubbleRun
is called exactly
n-1
times.
Make sure to test with:
scrambled array,
sorted array,
reverse sorted array.