News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

COnvert remainder to decimal form?

Started by devilhorse, October 25, 2008, 07:19:49 PM

Previous topic - Next topic

devilhorse

I know the result of the code snippet below is 51 with a remainder of 3. I have used dwtoa to display the quotient 51 in a textbox. I have also used dwtoa to display the remainder 3 in a textbox. The problem is I don't know how to show the remainder as a decimal instead of a whole number. I know the remainder is in edx. How do I divide the remainder by 7 and then display it in decimal form?


Mov Eax, 360
Cdq
Div 7

jj2007

Could be a nice exercise. Some time ago I did that using the FPU - see float$.

If you want a fixed number of decimals, multiply 360 with 1000, divide by 7 = 51428, and insert a dot at the third last position: 51.428

raymond

#2
At least, you do know that your remainder is always in EDX. After converting the integer part to ascii, assuming EDI points to the byte following the last integer digit,

   push  edx               ;save the remainder
   ....                    ;your code to convert EAX to ascii
   mov   byte ptr[edi],"."
   inc   edi
   mov   ecx,decimal_cnt   ;number of decimal digits required
   pop   eax               ;recover remainder
@@:
   mov   edx,10            ;<=
   mul   edx               ;<=
   div   divisor
   add   al,30h            ;convert to ascii
   mov   [edi],al          ;store it
   inc   edi               ;advance pointer
   mov   eax,edx           ;transfer remainder to eax
   dec   ecx
   jnz   @B                ;continue until count exhausted
   mov   byte ptr[edi],0   ;ready for display


The above should work regardless of the size of the divisor as long as it is not larger than 32 bits.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

devilhorse

 :UThanks for the help. I will use both methods when appropriate.

raymond

My apology. I forgot one important instruction in the provided code. I thus edited the original code for it.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com