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
Could be a nice exercise. Some time ago I did that using the FPU - see float$. (http://www.masm32.com/board/index.php?topic=9756.msg72641#msg72641)
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
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.
:UThanks for the help. I will use both methods when appropriate.
My apology. I forgot one important instruction in the provided code. I thus edited the original code for it.