Page 1 of 1

converting issue binary - decimal (assembly)

Posted: Mon Jul 02, 2007 1:06 pm
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.

Posted: Mon Jul 02, 2007 2:16 pm
by Combuster
divide by 10, print the remainder, repeat until the result is 0.

Posted: Mon Jul 02, 2007 3:36 pm
by Bughunter
See this topic for an example in code (if you need one):

http://www.osdev.org/phpBB2/viewtopic.php?p=99014#99014

Posted: Mon Jul 02, 2007 5:27 pm
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

Posted: Wed Jul 11, 2007 3:36 pm
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.

Posted: Fri Jul 13, 2007 3:31 pm
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:

Posted: Fri Jul 13, 2007 7:34 pm
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