title: Multiplying floats "manually" with integer operations
body: <p>I'm trying to implement a floating point multiply without using FP hardware instructions.</p>
  
  <p>I think my code works for the sign bit and exponents bits, but not the mantissa.</p>
  
  <p><strong>The general idea:</strong><br>
  1. Add exponents of those two numbers.<br>
  2. Multiply their mantissas.<br>
  3. Normalize the mantissa.<br>
  4. Add to exponent the part got from normalizing mantissa.<br>
  I ignore the sign bit for now since I test it on values higher than 0.</p>
  
  <p>And here is the problem: I tried to multiply those two mantissas and then - since the result would be in two registers edx:eax - shifting bits one by one from edx to eax meanwhile increasing exponent.
  But it doesn't seem to work, so I wonder if my idea is good, or maybe there is some better way to do it?</p>
  
  <hr>
  
  <p>Here is what I have already written in MASM:</p>
  
  <pre><code>mov eax, [ebp+8] ;put into eax one of numbers to multiply
  mov ecx, a ;in ecx is second number to multiply, constant = 1.8
  
  and ecx, 7F800000H ;mask to get exponent
  and eax, 7F800000H
  
  shr ecx, 23
  shr eax, 23
  
  sub ecx, 127
  sub eax, 127
  
  add ecx, eax ;exponent of the final number - later should be added part got from mantissa
  
  mov eax, [ebp+8]
  mov edx, a
  and eax, 007FFFFFH ;getting mantissa
  and edx, 007FFFFFH
  
  ; editor's note: unsure if there were any unlisted instructions
  ; between the two code in the original
  
  mul edx    ; multiply the mantissas
  
  mov ebx, 0
  
  spr:
      cmp edx, 0 ;check if edx is cleared out
      jne przesun
      je dalej
  
  przesun:
      inc ecx
      shr eax, 1 ;making space for new bit
      shr edx, 1 ;put bit to CF
      bts eax, 31 ;putting bit from CF   ; Bug #1, see Michael's answer
      jmp spr
  
  dalej:
      shr eax, 7
      shl ecx, 23
      add eax, ecx ;result of multiplying
  </code></pre>
  
  <p><strong>The result is 0 for every number I tried multiplying with 1.8.</strong><br>
  (atm I test it on number 15, so the result should be 27)</p>