LMU ☀️ CMSI 2210
COMPUTER SYSTEMS ORGANIZATION
Exam 2 Answers
  1. Write the following using NAND operators only:
    1. $A + B$
    2. $A \oplus B \oplus C$
    3. $0$
    4. $ABCD + \overline{C}$
    5. $A\overline{B} \oplus \overline{B + C}$
    Probably best to get the original expression into a “sum of products” form then do the trival mapping to NANDs:

    a) $A + B = \overline{(\overline{AA})(\overline{BB})}$

    b) $A \oplus B \oplus C = A\overline{B}\,\overline{C} + \overline{A}B\overline{C} + \overline{A}\,\overline{B}C + ABC = \overline{(\overline{A(\overline{BB})\overline{CC}})(\overline{\overline{AA}B\overline{CC}})(\overline{\overline{AA}(\overline{BB})C})(\overline{ABC})}$

    c) $0 = A\overline{A} = A\overline{A} + A\overline{A} = \overline{(\overline{A(\overline{AA})})(\overline{A(\overline{AA})})}$

    d) $ABCD + \overline{C} = \overline{(\overline{ABCD})C}$ --easiest one ☺

    e) $A\overline{B} \oplus \overline{B + C} = \overline{A}\,\overline{B}\,\overline{C} + A\overline{B}C = \overline{\overline{(\overline{AA})(\overline{BB})(\overline{CC})}(\overline{A\overline{BB}C})}$ --How did I get this? Truth tables!
  2. Write a logic formula of three variables, $A$, $B$, and $C$, that has the value 1 if and only if exactly one of the three variables is a 1.
    $A\bar{B}\bar{C} + \bar{A}B\bar{C} + \bar{A}\bar{B}C$
  3. In logic there is an operation called material implication, defined as follows: $A \supset B$ if and only if there is no way that $B$ can be false when $A$ is true. Express $A \supset B$ in two different ways: (a) using only the NOT and OR operators, and (b) using only the NOT and AND operators.
    $\overline{A} + {B}$      ...or you can write $\neg A \vee B$
    $\overline{A \overline{B}}$       ... or you can write $\neg(A \wedge \neg B)$
  4. Suppose that memory address 8 contains the value 0xFFFFFFFF. What does this code fragment do? Don't explain individual instructions; explain at a high level what the overall effect of the code fragment is.
        XOR   8
        SUB   8
    
    It negates the value in the accumulator. (It flips all the bits then adds one!)
  5. On the simple computer, explain (at a high level) what happens to the accumulator if the following seven statements are executed in sequence:
        STORE 20
        STORE 21
        ADD 20
        ADD 20
        STORE 20
        ADD 20
        ADD 21
    
    The value in it is multiplied by 7.
  6. Show the machine language for the following simple computer assembly language:
        X:    LOAD Y
              9023
        Z:    -70
              JGZ 9
              JLZ X
              MOD Z
        Y:    XOR X
    
    00000006
    0000233F
    FFFFFFBA
    F0000009
    E0000000
    80000002
    B0000000
  7. Write a complete program for the simple computer reads successive integer values from port 5, until the value read is a zero, and then writes the average of the nonzero values to port 10.
             JUMP  start
    sum:     0
    one:     1
    count:   0
    start:   IN    5
             JZ    compute     ; got zero so we are done reading
             ADD   sum
             STORE sum         ; sum += value read
             LOAD  count
             ADD   one
             STORE count       ; count += 1
             JUMP  start       ; go read the next number
    compute: LOAD  sum
             DIV   count
             OUT   10          ; output sum / count
    end:     JUMP  end
    
  8. One of the freshmen decided to "extend" the instruction set of the simple computer by adding sixteen new instructions, while keeping the basic word size of the machine 32 bits. How would such an extension affect the architecture of systems using this extended instruction set machine? (Hint: Think about memory and ports.)
    We would need 5 bits for the opcode, leaving only 27 bits for the operand. So the maximum amount of memory that could be addressed would be 128MiB and there could only by 128Mi ports. In other words the amount of addressable memory and the number of ports would each be cut in half.
  9. Suppose we wanted to write an assembly language that first read in a value from port 30, call it $n$, and then read in $n$ integers from port 31, storing them in successive memory locations starting at memory location 100. Can we do this on the simple computer? If so, give a program. If not, explain why not, and propose a new instruction (or instructions) for the computer that would enable it to be done.
    Technically the answer is yes, but only by using a technique we really never discussed in class, namely modifying the program as it is running, which wouldn’t be fair to make you figure out on a test. If you did figure out this technique, the program is:
            JUMP   start
    one:    1
    n:      0
    start:  IN     30
            STORE  n        ; number of items left to read
    read:   LOAD   n
            JLZ    done     ; no more left to read
            IN     31
    write:  STORE  100
            LOAD   write    ; OMG that is an instruction in memory
            ADD    one
            STORE  write    ; OMG we are changing our program (cooooooool)
            LOAD   n
            SUB    one
            STORE  n        ; count down number of items left to read
            JUMP   read
    end:    JUMP   end
    
    (Technically this program doesn't work if you ask it to read more than 268435455 items—do you see why?).

    I will also accept an answer of “No, because we don’t know the memory address to write to before the program is run, and our computer has no way to use a computed memory address.” In this case, a convenient new instruction would be STOREINDIRECT x, which would fetch the value in memory address $x$ (call it $y$), and then store the value in the accumulator into address $y$. By the way, all real computers actually do this.