converting issue binary - decimal (assembly)

Programming, for all ages and all languages.
Post Reply
Ninjarider
Member
Member
Posts: 62
Joined: Fri Jun 29, 2007 8:36 pm

converting issue binary - decimal (assembly)

Post by Ninjarider »

have a little function that takes a string and can extract usable number out of the string for math. now i need to be able to take a value in ax and convert it back to something the user understands.

had it working. lost the code and cant rememeber even were to start.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

divide by 10, print the remainder, repeat until the result is 0.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Bughunter
Member
Member
Posts: 94
Joined: Mon Dec 18, 2006 5:49 am
Location: Netherlands
Contact:

Post by Bughunter »

See this topic for an example in code (if you need one):

http://www.osdev.org/phpBB2/viewtopic.php?p=99014#99014
Ninjarider
Member
Member
Posts: 62
Joined: Fri Jun 29, 2007 8:36 pm

Post by Ninjarider »

thnx much you'll answer what was going to be my next question. sweat.

im not able to access it but does anyone of the top of there heads rmemeber what that command is in asm.

never mind just found an online refrence. sweat
User avatar
liquid.silver
Member
Member
Posts: 46
Joined: Sat Jun 30, 2007 12:07 pm
Location: South Africa
Contact:

Post by liquid.silver »

Ninjarider wrote:thnx much you'll answer what was going to be my next question. sweat.

im not able to access it but does anyone of the top of there heads rmemeber what that command is in asm.

never mind just found an online refrence. sweat
Sorry for the off-topic post, but don't you mean "sweet"? It made me laugh though, so it was funny :lol:
divide by 10, print the remainder, repeat until the result is 0.
This would print the number in reverse order. You must use recursion to print the number correctly.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

liquid.silver wrote:You must use recursion to print the number correctly.
That's not a 'must'. You can print right-to-left straight away or reverse it separately. No recursion needed for that :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Ninjarider
Member
Member
Posts: 62
Joined: Fri Jun 29, 2007 8:36 pm

Post by Ninjarider »

quick silver

thnx for correcting my misspelling on that. its just somthing i say when i either get something to work or understand something.


as far as recursion. if done correctly there is no recursion of any sort needed at all. if you know the length that the number wil make you can createa a buffer call x to hold {lets say 10 characters} create another label or variable right at the end of it called y

std \set our direction flag
mov di, offset y -1
@@: \the begining of our loop
...
... \all our code to break register (e)ax to characters
stosb
... \check to see if our register has reached 0
cld \clear our direction flag

then when your done you can print the string x and the null (0) characters will not appear (if there are any). so by doing this we need no recursion.


if you ask how it works:
if we have a variable x and that variable starts at linear address 7e00h
we then set di equal to the 7e00h
if the direction flag is clear. when we move information to ram using the stos function it will store the character for you and increment di properly for us. so that the next stor function would put a character at 7e01h

with the direction flag set. whenever we use a stor function to move something to memory it decrements di so that the next character would be stored at 7dffh

thats atleast in assembly
Post Reply