2022 23 5a

Computer Organization and Architecture2022-2310 marksNumericalInstruction types, formats, instruction cycles and sub cycle

Write a program to evaluate the arithmetic statement. P = ((X - Y + Z) * (A ^ B))/( C ^ D * E) By using (i) Two address instructions (ii) One address instructions (iii) Zero address instructions

Write a program to evaluate the arithmetic statement. P = ((X - Y + Z) * (A ^ B))/( C ^ D * E) By using (i) Two address instructions (ii) One address instructions (iii) Zero address instructions

The statement is

$$P = \frac{(X - Y + Z) \times (A ^ B)}{(C ^ D \times E)}$$

Here the caret is taken as a binary operator, written POW. So $A ^ B$ is the instruction POW. The same order of evaluation is used in all three programs: first $(X - Y + Z)$, then $A ^ B$, then the product of both. Then $C ^ D$, then multiply by $E$, and last the division.

(i) Two-address instructions. The first operand is both a source and the destination.

InstructionMeaning
MOV R1, XR1 = X
SUB R1, YR1 = X - Y
ADD R1, ZR1 = X - Y + Z
MOV R2, AR2 = A
POW R2, BR2 = A ^ B
MUL R1, R2R1 = (X - Y + Z) * (A ^ B)
MOV R2, CR2 = C
POW R2, DR2 = C ^ D
MUL R2, ER2 = C ^ D * E
DIV R1, R2R1 = numerator / denominator
MOV P, R1P = R1

(ii) One-address instructions. Every instruction uses the accumulator AC as the other operand, and T1 and T2 are temporary memory locations.

InstructionMeaning
LOAD XAC = X
SUB YAC = X - Y
ADD ZAC = X - Y + Z
STORE T1T1 = AC
LOAD AAC = A
POW BAC = A ^ B
MUL T1AC = (A ^ B) * T1
STORE T1T1 = numerator
LOAD CAC = C
POW DAC = C ^ D
MUL EAC = C ^ D * E
STORE T2T2 = denominator
LOAD T1AC = numerator
DIV T2AC = numerator / denominator
STORE PP = AC

(iii) Zero-address instructions. These use a stack. PUSH puts a value on the stack. An operation takes the top two values, applies the operation, and pushes the result. For SUB and DIV, the lower element is the left operand. The expression in reverse Polish form is $X,Y - Z + A,B ^ \times C,D ^ E \times /$, and the program is:

InstructionStack after it (top on right)
PUSH XX
PUSH YX, Y
SUBX-Y
PUSH ZX-Y, Z
ADDX-Y+Z
PUSH AX-Y+Z, A
PUSH BX-Y+Z, A, B
POWX-Y+Z, A^B
MULN (numerator)
PUSH CN, C
PUSH DN, C, D
POWN, C^D
PUSH EN, C^D, E
MULN, C^D*E
DIVN / (C^D*E)
POP Pstack empty

The three programs use 11, 15 and 16 instructions. As the number of address fields drops, the program becomes longer, but each instruction becomes shorter.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.

Up nextWhat are the differences between hardwired and micro-programmed control unit?