Computer Organization - Sec.4 Quiz #2 Solutions
 
Problem #1 - 10 points
Problem #2 - 10 points
Problem #3 - 10 points
Problem #4 - 10 points
Total      - 40 points

1. The Control Unit(CU) controls the information flow in the CPU. Upon receiving op-code from Instruction Register(IR) and referring each bits of Condition Code Register(CCR), the CU determines a sequence of actions for that instruction. Each step is primitive operation defined as data flow from one unit(register, PC, ALU, etc.) to another.

    There are two different approaches to the design of CU; microprogrammed CU and random logic CU. In micoprogrammed CU, each assembly language instruction consists of a sequence of microinstructions (control signals) called microprogram. The microprograms are stored in control memory (ROM) in the CPU. For each op-code from IR, the CU leads to the starting address of corresponding microprogram from which microinstructions are executed step by step. In Random Logic CU, logic gates are hard-wired into the CU so that each op-code has its own circuit. In general, microprogrammed CU requires ROM for control memory while random logic CU requires gates and flip-flops for logic circuit.

    Microprogrammed CU is flexible. A random logic CU is dedicated to a specific CPU and cannot be easily modified for different CPU's while micoprogrammed CU can be easily adapted to different CPU's with little modification. System improvement or changes are easily done by changing the microprogram. And you can add instructions of your choice to the instruction set by modifying the micoprogram.

    Random logic CU is faster. In random logic CU, logic circuits for each instructions are optimized while  microprogrammed CU uses general-purpose microinstructions to implement each instructions. And microprogrammed CU must read microinstructions from microprogram memory at each step and it makes the microprogrammed CU even slower.

    The cost for each approach depends on the complexity of system. For simpler system, random logic CU is suitable because the cost for a few gates and flip-flops are much lower than that of ROM. For complex system, the cost for ROM is much lower that that of gates and flip-flops, so microprogrammed CU is suitable in term of cost.


2.
(a) Register Indirect with Index

    An operand consists of two registers - one of them must be Address Register which holds base address and the other may be Address Register or Data Register - and displacement. The effective address is the sum of two registers and displacement. The range of displacement is -128 to 127 because the displacement is 8-bit value. For example, MOVE.B 8(A0,A1),D1 gets the effective address by calculating 8+[A0]+[A1], then fetches memory contents and then copies it to D1.

(b) Register indirect with Predecrement

    The contents of address register is decremented - by 1, 2, or 4 according to the extension of instruction - before actual memory contents is fetched. For example, ADD.L D0,-(A0) decrements the contents of A0 by 4 and then adds the contents of D0 to the memory location pointed by A0.


3.
        ORG       $400
A_LOC   EQU       $2000
B_LOC   EQU       $2004
*
        MOVE.L    A_LOC,D0       # D0 holds A
        MOVE.L    B_LOC,D1       # D1 holds B
        CMP.L     D1,D0          # A > B ?
        BGT       A_GREAT
        CMP.L     #0,D0          # A < 0 ?
        BLT       A_NEG
        ADD.L     D0,B_LOC       # B = A + B
        BRA       DONE
A_NEG   CLR.L     A_LOC          # A = 0
        BRA       DONE
A_GREAT CMP.L     #0,D1          # B < 0 ?
        BLT       B_NEG
        ADD.L     D1,A_LOC       # A = A + B
        BRA       DONE
B_NEG   CLR.L     B_LOC          # B = 0
*
DONE    STOP      #$2700
        END       $400


4.
SEARCH  MOVE.B    #99,D1         # D1: loop counter initialized to 99 (means 100 times)
LOOP    CMP.B     (A0),D0        # compare current table entry with target
        BEQ       DONE           # if found, go to the end of program
        ADDA.B    #1,A0          # move to the next table entry
        DBRA      D1,LOOP
DONE    RTS