HW #2 Computer Architecture

Due: 9/17/04 (F)

1. Compare zero-, one-, two-, three-address, and the load & store machines by writing programs to compute

X = A + B * C - E;

Y = A / (E * C - D);

for each of the five machines. The instructions available for use are as follows:

3 Address 2 Address 1 Address

(Accumulator machine)

0 Address

(Stack machine)

MOVE (X Y) MOVE (X Y) LOAD M PUSH M
    STORE M POP M
ADD (X Y + Z) ADD (X X + Y) ADD M ADD
SUB (X Y - Z) ADD (X X - Y) SUB M SUB
MUL (X Y * Z) MUL (X X * Y) MUL M MUL
DIV (X Y / Z) DIV (X X / Y) DIV M DIV

  Notes:

"SUB M" performs

AC = AC - M

"DIV M" performs

AC = AC / M

Notes:

"SUB" performs

POP T

POP T2

T3 = T2 - T

PUSH T3

"DIV" performs

POP T

POP T2

T3 = T2 / T

PUSH T3

Load/Store Architecture - operands for arithmetic operations must be from/to registers. For example, to perform the high-level statement "Z = X - Y" we need the code:

LOAD R2, X

LOAD R3, Y

SUB R4, R2, R3

STORE R4, Z

2. Assume 8-bit opcodes, 32-bit absolute addressing, 5-bit register numbers, and 32-bit operands. Compute the number of bits needed in programs from question 1 by completing the following table.

  3 Address 2 Address 1 Address 0 Address Load & Store
Number of bits needed to store the program          
Number of bits of data transferred to and from memory          
Total number of bits read and written while the program executes          

3.

  Register File     Memory
R0:     (Label X:) 0 4
R1: 20   4 5
R2: 4   8 6
R3: 8   12 7
R4: 12   16 8
R5: 16   20 9
R6: 20   24 10
      28 11
      32 12
      36 13
PC: 36   40 14

For each AL statement listed below, determine the value loaded into register R0. Always assume the above unmodified register and memory values.
Assembly Language Statement Type of addressing R0's Register Value After Execution
Load R0, X Direct  
Load R0, (R1) Register-Indirect  
Load R0, 8(R1) Base-register/Displacement  
Load R0, -8(R1) Base-register/Displacement  
Load R0, X(R3) Indexing