LMU ☀️ CMSI 2210
COMPUTER SYSTEMS ORGANIZATION
HOMEWORK #3 Due: 2018-03-22

Instructions

IF POSSIBLE, PLEASE WORK ON THESE PROBLEMS WITH A PARTNER. Turn in only one set of solutions with both of your names on the cover sheet. Do not partition the work; both team members must understand all of the answers.

Turn in a printed packet of answers on 8.5 × 11 inch paper with a single staple in the upper-left corner. Answers should be neatly typeset. Sloppy work will get you a little discretionary point mark down.

Problem 9 should also be dropped into a personal private repo on Github called nasm-hello-world, because everyone should have electronic records of their programs. Make sure the repo is private to reduce the temptation for copying. String with the next assignment, we’ll be on GitHub classroom.

Readings

Read Chapters 2 and 3 in the textbook thoroughly so you understand all of the concepts presented. Lectures and homework and googling homework answers is not enough for you to master this material.

The Problems

  1. 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. Do NOT draw the circuit; just write two formulas; one for computing $X$ and one for computing $Y$.
  2. Draw a logic circuit that compares two 2-bit signed numbers as follows. It should have four inputs $a_1$, $a_0$, $b_1$, and $b_0$. $a_1a_0$ is a 2-bit signed number (call it $a$) and $b_1b_0$ is a 2-bit signed number (call it $b$). The circuit has one output, $c$, which is $1$ if $a > b$ and $0$ otherwise.
  3. 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.
    1. Clear all even numbered bits.
    2. Set the last three bits.
    3. Compute the remainder when divided by 8.
    4. Make the value -1
    5. Complement the two highest order bits
    6. Compute the largest multiple of 8 less than or equal to the value itself
  4. For the sample single-accumulator computer discussed in class, write a complete assembly language program that sends the values 0 through 255 out to port 0x8.
  5. Translate your assembly language program in the previous problem to machine language.
  6. For the sample single-accumulator computer discussed in class, write a complete assembly language program that computes a greatest common divisor. Assume the two inputs are read in from port 0x100. Write the result to port 0x200.
  7. For the sample single-accumulator computer discussed in class, give a code fragment, in assembly language, that swaps the accumulator and memory address 0x30AA.
  8. For the sample single-accumulator computer discussed in class, give a code fragment, in assembly 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.
  9. Write a NASM program that prints 最近怎么样? to the terminal. Use system calls, not the C library.
  10. Explain, at a high-level, what this 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
    
    Also state as briefly as possible why that effect happens.