forked from MightyPork/crsn
parent
c8d01b6151
commit
af52270a29
@ -0,0 +1,44 @@ |
||||
( |
||||
; using a coroutine as a generator |
||||
|
||||
(spawn r15 fibo) |
||||
|
||||
(ld r0 20) |
||||
(:next) |
||||
|
||||
(ld r1 @r15) ; Read a yielded value |
||||
(call printnum r1) |
||||
(lds @cout ", ") |
||||
|
||||
(dec r0) |
||||
(j.nz :next) |
||||
(ld @cout '\n') |
||||
(halt) |
||||
|
||||
(proc fibo |
||||
(ld r0 0) |
||||
(ld r1 1) |
||||
(:x) |
||||
(yield r1) |
||||
(add r2 r0 r1) |
||||
(ld r0 r1) |
||||
(ld r1 r2) |
||||
(j :x) |
||||
) |
||||
|
||||
(proc printnum num |
||||
(mkbf r15) |
||||
(ld r1 num) |
||||
(tst r1 (<0? (mul r1 -1))) |
||||
(:next) |
||||
(mod r0 r1 10) |
||||
(add r0 '0') |
||||
(bfrpush @r15 r0) |
||||
(div r1 10 (z? |
||||
(tst num (<0? (bfrpush @r15 '-'))) |
||||
(lds @cout @r15) |
||||
(del @r15) |
||||
(ret))) |
||||
(j :next) |
||||
) |
||||
) |
Loading…
Reference in new issue