![]() |
Jupyter at Bryn Mawr College |
|
|
Public notebooks: /services/public/dblank / CS240 Computer Organization / 2015-Fall / Assignments |
Welcome aboard to CS240: Priciples of Computer Organization!
Due: Wednesday, Sep 2, 2015, 2:40pm. Print out, and bring to class.
This first assignment introduces a number of new things:
Read chapter 1, and write down 6 questions for discussion in class on Wednesday, Sep 2:
For this, our "Hello, World" program in Machine Language, our goal is to:
We create a machine language program by putting machine language code in a Jupyter cell, and pressing Shift+Enter, or pressing the triangle button at top of page. This will assemble the code and place it into memory.
A machine language program always starts with where in memory the code should be placed, its "origin". We'll often use x3000 as a generally open place in memory, but it could be anywhere. We use the .ORIG directive.
Then, we enter all of the machine language instructions (see next).
Finally, we signal to the assembler that this is the end, using the .END directive.
For our first program, we will use two instructions: add and halt.
The add instruction always starts out with 0001. Then it is followed by the destination register, as source register, the number 1, and a 5-bit binary number.
In shorthand, it does this:
Destination Register <- Source Register + 5-bit binary number
The halt instruction is long, but specific:
1111 0000 00100101
There are variations of this command, but for now, we'll just use it as it is.
Now we just put the .ORIG, code, and .END together in a cell, and press Shift+Enter:
.ORIG x3000
0001 000 000 1 00001
1111 0000 00100101
.END
There, you just assembled your first program! What you are seeing is:
But we didn't actually run the program. To do that, we use a Jupyter Calysto LC3 magic, %exe. Enter %exe
in a cell, and press Shift+Enter:
%exe
You just ran your first machine language program! What did it do? Just what we told it:
Destination Register (R0) <- Source Register (R0) + 5-bit binary number (00001)
So, if it worked correctly, you should see R0 has the value 1.
You can run it again:
%exe
And now R0 contains 2.
To reset the register, use:
%reg REGISTER VALUE
So, to reset register 000 to 0 use:
%reg 000 0
You can continue to run it again, or set registers to different values.
For the following questions, using only the add instruction, do the following: