Page 1 of 1

print_int in nasm

Posted: Thu May 04, 2006 11:00 pm
by norc-
I'm building an asm kernel based on josh's rudimentary kernel http://www.mohanraj.info/josh4.jsp. I have written a function which converts a single digit to its equivalent char, but now i want to be able to print numbers, not just digits.
This is my plan:
1) divide the [original] by 10 until it is less than 10, saving how many divides it took [n]
2) then print the single digit
3) [m]=10^[n]
4) calculate [original]=[original]-[m]*digit, save [original]
5) do this until [original]!=0

Is this ok?

Thanks a lot!

ps: i'm fairly new to asm

Re: print_int in nasm

Posted: Thu May 04, 2006 11:00 pm
by mrkaktus
Don't you think that easier would be to decide first which type of numer your function will display and then divide it every time by base and show the constant from division. Then the rest is the new numer to divide in next loop.

example:

Your function operates on integers from 0 to 2^32 (unsigned long in C).

So you wold have maximum 10 division, starting from dividing by 10^9
and next division is division of the rest from first division by 10^8 etc.

number: 1234567890
gives 1 and rest 234567890.
etc..

I think this is the easiest way :).

Re: print_int in nasm

Posted: Mon May 08, 2006 11:00 pm
by norc-
I guess that would be easier...
Thanks, I'll give it a whirl,
norc-