Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2015/digital-systems-linear-algebra-introduction-to-formal-proof/6/e/solution

Fix sub to mean . If the depth-minimizing order evaluates the right operand before the left operand , the stack ends in , so ordinary sub would compute the wrong sign. Two possible instruction set architecture extensions are:
  • Add swap, with . After computing and then , use swap; sub to obtain . One general zero-address instruction handles every noncommutative binary operation and is useful elsewhere, but each reversed evaluation needs an extra instruction and extra execution time. It can be implemented without an additional operand stack slot.
  • Add reverse-operand variants, such as rsub with , and analogously reverse division and other required operations. After computing and then , a single rsub obtains . This avoids the extra executed swap, but requires more opcodes and decoder support, usually one reverse form for each affected operation.
Both preserve the same peak operand stack bound:
The first trades extra dynamic instructions for a smaller instruction set; the second trades a larger instruction set for fewer executed instructions. Neither extension makes order-sensitive side effects safe to reorder.

New to topics? Read the docs here!