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.
 
 
crsn/examples/itoa.csn

24 lines
558 B

(
; This is an example implementation of itoa using a buffer of characters
(ld r0 -123456789)
(mkbf r1)
(call itoa r1 r0)
; print it
(:pn) (bfrpop @cout @r1 (em? (ld @cout '\n') (halt))) (j :pn)
(halt)
(proc itoa buf num
(ld r1 num)
(tst r1 (<0? (mul r1 -1)))
(:next)
(mod r0 r1 10)
(add r0 '0')
(bfrpush @buf r0)
(div r1 10 (z?
(tst num (<0? (bfrpush @buf '-')))
(ret)))
(j :next)
)
)