/ GENTLE PRIMER
/ Optimal Rule Selection
A Computer with an Accumulator
Let us consider a different kind of computer that uses an accumulator to compute values. The accumulator holds one of the operands of a computation, the other being given as a parameter of an instruction. The result is placed into the accumulator.
These are the instructions:
'action' ACCUPLUS(Variable) 'action' ACCUMINUS(Variable) 'action' LOADACCU(Variable) 'action' STOREACCU(Variable)ACCUPLUS(X) means Accu := Accu + X, ACCUMINUS(X) means Accu := Accu - X, LOADACCU(X) means Accu := X, STOREACCU(X) means X := Accu. Here is an incomplete specification of code generation:
'rule' Encode(assign(V,X)): AccuCode(X) STOREACCU(V) 'rule' AccuCode(plus(X, var(V))): AccuCode(X) ACCUPLUS(V) 'rule' AccuCode(minus(X, var(V))): AccuCode(X) ACCUMINUS(V) 'rule' AccuCode(var(V)): LOADACCU(V)(The specification is still incomplete because we only consider the case where the second operand of plus and minus is a variable. If it were be a more complex expression, we would have to introduce temporary variables.)