Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
792 B

; using a coroutine as a generator
(spawn r15 fibo)
(ld r0 20)
(ld r1 @r15) ; Read a yielded value
(call printnum r1)
(lds @cout ", ")
(dec r0)
( :next)
(ld @cout '\n')
(proc fibo
(ld r0 0)
(ld r1 1)
(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)))
(mod r0 r1 10)
(add r0 '0')
(bfrpush @r15 r0)
(div r1 10 (z?
(tst num (<0? (bfrpush @r15 '-')))
(lds @cout @r15)
(del @r15)
(j :next)