Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f15bd68
commit 34caea5
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(controller | ||
(assign p (const 1)) | ||
(assign c (const 1)) | ||
test-c | ||
(test (op >) (reg c) (reg n)) | ||
(branch (label rem-done)) | ||
(assign p (op *) (reg p) (reg c)) | ||
(assign c (op +) (reg c) (const 1)) | ||
(goto (label test-c)) | ||
rem-done) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(controller | ||
test-g | ||
(test (op ge?) (reg g) (reg x)) | ||
(branch (label sqrt-done)) | ||
(assign g (op imp) (reg g)) | ||
(goto (label test-g)) | ||
sqrt-done) | ||
|
||
(controller | ||
test-g | ||
(test (op <) ((op abs) ((op -) ((op sq) (reg g)) (reg x)))) | ||
(branch (label sqrt-done)) | ||
(assign g (op avg) (reg g) ((op /) (reg g) (reg x))) | ||
(goto (label test-g)) | ||
sqrt-done) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
;a | ||
|
||
(controller | ||
(assign continue (label expt-done)) | ||
expt-loop | ||
(test (op =) (reg n) (const 0)) | ||
(branch (label base-case)) | ||
(save continue) | ||
(assign n (op -) (reg n) (const 1)) | ||
(assign continue (label after-expt)) | ||
(goto (label expt-loop)) | ||
after-expt | ||
(restore continue) | ||
(assign val (op *) (reg b) (reg val)) | ||
(goto (reg continue)) | ||
base-case | ||
(assign val (const 1)) | ||
(goto (reg continue)) | ||
expt-done) | ||
|
||
;b | ||
|
||
(controller | ||
(assign p (const 1)) | ||
test-c | ||
(test (op =) (reg n) (const 0)) | ||
(branch (label expt-done)) | ||
(assign counter (op -) (reg n) (const 1)) | ||
(assign p (op *) (reg b) (reg p)) | ||
(goto (label test-c)) | ||
expt-done) |