sicp-ex-5.5



<< Previous exercise (5.4) | Index | Next exercise (5.6) >>


meteorgan

  
  
  
 using the example of factorial in the book. 
 (set-register-contents! machine 'n 2) 
  
 1. n = 2 
 (save continue) ;; stack: ((label fact-done)) 
 (save n)             ;;  stack (2 (label fact-done)) 
 (assign n (op -) (reg n) (const 1)) ;; n =1 
 (assign continue (label after-fact)) ;; continue: (label after-fact) 
  
 2. n =1. go to base-case 
 (restore n)      ;; n: 2; stack: ((label fact-done)) 
 (restore continue) ;; continue: label fact-done stack: ()