SICP 全笔记

Exercise 5.2. Use the register-machine language to describe the iterative factorial machine of exercise 5.1.

我们可以把 5.1 中画出来的两个图用下面的 register-machine language 来表示:

; TODO: declare the register and operation!
(data-path
 (registers
  ((name counter)
   ;...
   ))
 (operations
  ((name +)
   ())
  ((name *)
   ())
  ((name >)
   ())))

(constroller
    (assign product (const 1))
    (assign counter (const 1))
 test-p
    (test (op >) (reg counter) (const 0))
    (branch (label done))
    (assign t2 (op +) (reg counter) (const 1))
    (assign t1 (op *) (reg product) (reg counter))
    (assign product (reg t1))
    (assign counter (reg t2))
    (goto (label test-p))
 done)
 

嘿!这不就是汇编吗?