Chapter 5, Computing with Register Machines

Exercise 5.2


1
2
3
4
5
6
7
8
9
10
(controller
 (assign product (const 1))
 (assign counter (const 1))
 fact-loop
   (test (op >) (reg counter) (reg n))
   (branch (label fact-done))
   (assign product (op *) (reg product) (reg counter))
   (assign counter (op +) (reg counter) (const 1))
   (goto (label fact-loop))
 fact-done)