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

3 Address 2 Address 1 Address 0 Address Load & Store
MUL X, B, C

ADD X, A, X

SUB X, X, E

MUL Y, E, C

SUB Y, Y, D

DIV Y, A, Y

MOVE X, B

MUL X, C

ADD X, A

SUB X, E

MOVE T, E

MUL T, C

SUB T, D

MOVE Y, A

DIV Y, T

LOAD B

MUL C

ADD A

SUB E

STORE X

LOAD E

MUL C

SUB D

STORE Y

LOAD A

DIV Y

STORE Y

PUSH A

PUSH B

PUSH C

MUL

ADD

PUSH E

SUB

POP X

PUSH A

PUSH E

PUSH C

MUL

PUSH D

SUB

DIV

POP Y

LOAD R1, B

LOAD R2, C

MUL R3, R1, R2

LOAD R1, A

ADD R3, R3, R1

LOAD R4, E

SUB R3, R3, R4

STORE R3, X

MUL R3, R4, R2

LOAD R4, D

SUB R3, R3, R4

DIV R3, R1, R3

STORE R3, Y

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 6 x (8+3x32) = 624 9 x (8+2x32) = 648 12x(8+32) = 480 10x(8+32) +

6x8 = 448

7x(8+32+5) +

6x(8+5+5+5)=

453

Number of bits of data transferred to and from memory 6x3x32 = 576 3x2x32 + 6x3x32 = 768 12x32 = 384 10x32 = 320 7 x 32 = 224
Total number of bits read and written while the program executes 1,200 1,416 864 768 677

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 4
Load R0, (R1) Register-Indirect 9
Load R0, 8(R1) Base-register/Displacement 11
Load R0, -8(R1) Base-register/Displacement 7
Load R0, X(R3) Indexing 6 if you assume R3 contains a byte displacement

or

12 if you assume R3 contains an index into an array