42 lines
753 B
Text
42 lines
753 B
Text
fn itoa(number: i32) -> i32 {
|
|
let count: i32 = 0;
|
|
let is_negative = number < 0;
|
|
|
|
if is_negative {
|
|
number = -number;
|
|
}
|
|
|
|
loop {
|
|
let ch = (number % 10) + 0x30;
|
|
store_i32_8(count + 8, ch);
|
|
|
|
number = number / 10;
|
|
count = count + 1;
|
|
|
|
if number == 0 {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if is_negative {
|
|
store_i32_8(count + 8, 45);
|
|
count = count + 1;
|
|
}
|
|
|
|
let i: i32 = 0;
|
|
loop {
|
|
let swap_to = count - i + 7;
|
|
let swap_from = i + 8;
|
|
|
|
let tmp = load_i32_8(swap_to);
|
|
store_i32_8(swap_to, load_i32_8(swap_from));
|
|
store_i32_8(swap_from, tmp);
|
|
|
|
i = i + 1;
|
|
if i >= count / 2 {
|
|
break;
|
|
}
|
|
}
|
|
|
|
count
|
|
}
|