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
a0,b0,out0)
projects/3/a7
RAMxx
:
RAM8
should be built out of 8 Logisim Register
components (under Memory
)RAMxx
should be built out of as few as possible previously built smaller RAMyy
; use the Logisim RAM
component (under Memory
) and pick the right values under Properites
:
RAM128
equivalent adjust the properties so that at the top it says RAM 128 x 16
AA,BB,CC
respectivelyRAM8.png
AA,BB,CC
respectivelyRAMxx-first.png, RAMxx-mid.png, RAMxx-last.png
Register.hdl
(if you do, testing will be very slow)RAMxx
:
RAM8
should be built out of 8 Register
chipsRAMxx
should be built out of as few as possible RAMyy
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, wheren
is the size of the array.
Here is a visualization of the process from Wikipedia:// 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); } }
Hint: Ensure that![]()
SP
is loaded with 0x100
(see array example at top).
Hint: Instead of size you might find it more convenient to have a variable that represents number of pairs.
Hint: In general, the meaning of a comparison should be flipped from what it would be in CS111.
Hint: An if
statement is set up similar to a loop. It still has a jump/branch
that is designed to skip over the section that
normally would have been executed. The same structure was used for the loop, where the focus was on when to stop looping and to skip the body.
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.
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.
Ensure that when bubbleRun
finishes register R10
is set to 0 if no swap was made during the run; otherwise, R10
should be set to 1 to indicate a comparison took place. Do not count how many comparisons were made.
Make sure to test with: scrambled array, sorted array, reverse sorted array.
Keep looping around the code from bubbleRun
as long as register R10
is 1.
Make sure to test with: scrambled array, sorted array, reverse sorted array.
bubbleRun
loops less and less each time. That is:
bubbleRun
, it loops over all pairsbubbleRun
, it loops over all but 1 pairsbubbleRun
, it loops over all but 2 pairsMake sure to test with: scrambled array, sorted array, reverse sorted array.