Advertisement
Thomas_Cloostermans

Oplossing reg-exp recursief

Apr 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.89 KB | None | 0 0
  1. ; oefening 4
  2. (assemble-and-run '(start
  3.                     (assign v1 (const 3))
  4.                     (assign v2 (const 5))
  5.                     (assign cont (label stop))
  6.                     (goto (label start-expt-rec))
  7.  
  8.                     start-expt-rec
  9.                     (test (op =) (reg v2) (const 0))
  10.                     (branch (label return-1))
  11.                     (save cont)
  12.                     (assign cont (label rec-exp))
  13.                     (assign v2 (op -) (reg v2) (const 1))
  14.                     (goto (label start-expt-rec))
  15.  
  16.                     rec-exp
  17.                     (assign res (op *) (reg v1) (reg res))
  18.                     (restore cont)
  19.                     (goto (reg cont))
  20.                    
  21.                    
  22.                     return-1
  23.                     (assign res (const 1))
  24.                     (goto (reg cont))
  25.  
  26.                     stop))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement