26 lines
403 B
Plaintext
26 lines
403 B
Plaintext
import mem
|
|
import sys
|
|
|
|
number(x Int) {
|
|
length := 20
|
|
buffer := mem.alloc(length)
|
|
address, count := itoa(x, buffer, length)
|
|
sys.write(1, address, count)
|
|
mem.free(buffer, length)
|
|
}
|
|
|
|
itoa(x Int, buffer Pointer, length Int) -> (Pointer, Int) {
|
|
end := buffer + length
|
|
tmp := end
|
|
digit := 0
|
|
|
|
loop {
|
|
x, digit = x / 10
|
|
tmp -= 1
|
|
tmp[0] = '0' + digit
|
|
|
|
if x == 0 {
|
|
return tmp, end - tmp
|
|
}
|
|
}
|
|
} |