print_int in nasm

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
norc-
Posts: 2
Joined: Mon May 01, 2006 11:00 pm
Location: si

print_int in nasm

Post 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
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: print_int in nasm

Post 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 :).
norc-
Posts: 2
Joined: Mon May 01, 2006 11:00 pm
Location: si

Re: print_int in nasm

Post by norc- »

I guess that would be easier...
Thanks, I'll give it a whirl,
norc-
Post Reply