On Fri, 8 Dec 2017 14:26:43 +0100, "wolfgang kern"    
   wrote:   
   >...   
   >you found a max.value ? OK, me once too!   
   >...   
   Yes, but you use the shifted version here. I used the one that gives   
   a 32 bit quotient in edx without shifting.   
      
   I wrote a ROSASM program that poped up a dialog where I could input   
   the divisor, and it calculated the reciprocal and immediately went   
   into the loop and printed the first number that gives a bad result.   
   And there was a x+1 checkbox to tell if the input should be increased   
   by 1.   
      
   Here is what some of them gave:   
      
   Divisor Reciproal hightest number   
    3 0x55555555 4296967294 x+1 on   
    5 0x33333333 4294967294 x+1 on   
    10 0x1999999A 1073741828 x+1 off   
    15 0x11111111 4294967294 x+1 on   
      
   >here is a copy of what I tried for 32 bit after Terje showed me the   
   >error with my 0x1999999A reciprocal some years ago.   
   >(haven't checked if this can be modified for 64 bit):   
   >..   
   >BIN2DEC:   
   >.ALIGN 64   
   > mov eax,0xffffffff ;max. num test /others tested as well   
   > mov ebx,0xcccccccd ;2^35/10   
   > mov edi,BUFFER+10 ;point to end because stored backwards   
   > mov [edi],byte 0 ;Z-terminator   
   >.ALIGN 4   
   >L1:   
   > mov ecx,eax ;copy initial value or last quotient   
   > mul ebx ;divide   
   > dec edi ;goes backward   
   > shr edx,3 ;-> 2^32   
   > lea esi,[edx+edx*8] ; *9 (SUB ecx,edx*10)   
   > sub ecx,edx ;-*1   
   > sub ecx,esi ;-*9   
   > mov eax,edx ;prepare for next   
   > or ecx,+30h ;   
   > test edx,edx ;only until nothing more   
   > mov [edi],cl ;   
   > jnz L1 ;   
   > ret ;edi points to first character (MSD) yet   
   >.ALIGN 64 ;must be at least one cache line away from code   
   >BUFFER: dup 11 ? ;ASCII-Z num w/o leading Zeros   
   >-----------   
   Thanks, I will take a closer look, if a can use it somehow!   
   --   
   aen   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|