CMSI 284: Homework Assignment #4
The following guidelines are expected for all homework submissions:
- All homework must be typed. Homework which is not typed will be returned ungraded and will be
subject to the late homework guidelines as set out on the syllabus page. PLEASE DO NOT scribble
something on lined paper and rip it out of your spiral notebook — hanging chads went out
with the presidential election in 2000.
- I don't care too much about what font you use or how large your margins are; however, you might
want to check out a monospaced font for typing code, as it will be easy to see the indentations.
- Speaking of indenting, PLEASE DON'T USE TABS TO INDENT YOUR CODE. Tabs can often get interpreted
differently by different computers and applications, and could make code that is nicely formatted
on your computer look
all over the map
on my computer or printer. USE SPACES INSTEAD.
You can set up almost every modern text editor to insert spaces whenever you press the TAB key, or
you can simply pound the spacebar.
- Work with a partner. I can't stress this enough; part of this policy is don't
split up the work – WORK TOGETHER on the assignment; DO NOT
DIVIDE UP THE WORK!. Doing assignments this way mimics an industry code development model
called
pair programming
which is part of the Extreme Programming [Agile] software development
method. Feel free to collaborate in your pairs as much as you want, doing the entire assignment
together. Only submit ONE copy for the both of you.
- DO NOT share your work between groups. Doing so will count as plagiarism. If you
wish to discuss solutions with another group over coffee in the Lair, that's fine as long as it is
kept at the conceptual and you don't share your code between groups. Each group needs to
turn in its own version of the solutions.
- Repeat: you only need to turn in one copy per group.
- Submit your homework through GitHub, in your repository, and be sure to make
me a contributor so I have access. I cannot evaluate what I cannot see! If
I can't upload to your repo, you will not get an evaluation for the assignment.
Problems for Assignment #4
- Consider the function with three inputs (A,B,C) and two outputs (X,Y) that works like this:
A B C | X Y
---------+------
0 0 0 | 0 1
0 0 1 | 0 1
0 1 0 | 0 1
0 1 1 | 1 1
1 0 0 | 1 0
1 0 1 | 1 1
1 1 0 | 1 0
1 1 1 | 1 1
Design two logic circuits for this function, one using AND, OR and NOT gates only, and one using
NAND gates only. You DO NOT HAVE to draw the circuit, but it might
be helpful to do that to visualize and trace the logic. However, for this question you are only
required to write the two formulas — one for computing X
and one for computing
Y
. They can take the form of a logical equation such as
X := A and B
or such as
Y := not-B and (A or C)
.
- Draw a logic circuit that compares two 2-bit signed numbers as follows. It should have four inputs
a1, a0, b1, and b0. a1a0 is a
2-bit signed number (call it a) and b1b0 is a 2-bit signed number (call it b).
The circuit has one output, c, which is 1 if a > b and 0 otherwise.
- Given a 32-bit register, write logic instructions to perform the following operations. For parts (c)
and (f) assume an unsigned interpretation; for part (d) assume a signed interpretation.
- Clear all even numbered bits.
- Set the last three bits.
- Compute the remainder when divided by 8.
- Make the value -1
- Complement the two highest order bits
- Compute the largest multiple of 8 less than or equal to the value itself
- For the sample single-accumulator computer discussed in class, write a complete assembly language
program in the
stanley/penguin
language that sends the values 0
through
255
out to port 0x8
. NOTE: the machine code for this will be written in
the next problem.
- Translate your assembly language program in the previous problem to machine language.
- For the sample single-accumulator computer discussed in class, write a complete assembly language
program in the
stanley/penguin
language that computes a greatest
common divisor. Assume the two inputs are read in from port 0x100
. Write the result
to port 0x200
. You do not need to write machine code for this problem.
- For the sample single-accumulator computer discussed in class, give a code fragment, in assembly
language of the
stanley/penguin
language, that swaps the accumulator
and memory address 0x30AA
. You do not need to write machine code for this problem.
- For the sample single-accumulator computer discussed in class, give a code fragment, in assembly
language of the
stanley/penguin
language that has the effect of
jumping to the code at address 0x837BBE1
if the value in the accumulator is greater
than or equal to 0
. You do not need to write machine code for this problem.
- Part 1 of 2: Explain, at a high-level, what the following sequence of instructions
does. In other words, suppose a programmer has stored data in
r8
and r9
.
After executing these instructions, what does the programmer notice about the data?
xor r8, r9
xor r9, r8
xor r8, r9
Part 2 of 2: Also state as briefly as possible why that effect happens.