; The Algorithm I used:
; Split the string into substrings, e.g. the sign of the mantissa, the whole number part,
; the fractional part, sign of the exponent and the exponent. I convert the three number
; substrings into integers. I then push these numbers and their signs (as booleans, 0 or 1)
; onto the stack as parameters and call a routine to construct the floating point
; number. This routine uses the coprocessor to do all the work. Here is some example
; code to help you out. I would recommend that you study this carefully and not just
; blindly copy and use it! Also, I don't claim this is the best way to do the conversion --
; it is probably the most straightforward of the algorithms.

;================================================================================
; Used for debugging.
;================================================================================
PrintFloat:
         Enter 0
         Push_Regs ebx, ecx, edx, esi, edi

         Make_Local_Str flst_len, flst_str, 'Floating number -> %.6e', 10, 0

         fld dword [ebp + 8]
         sub esp, 8
         fstp qword [esp]
         push dword flst_str
         call printf
         add esp, 12

         Pop_Regs ebx, ecx, edx, esi, edi
         Leave
         ret

;================================================================================
; This routine takes a whole_num, fraction, fraction_cnt, exponent, neg_mantissa,
; neg_exponent, float_result and constructs a floating point number using the 
; coprocessor. The result is returned in float_result on the stack.
;================================================================================
ConstructFloat:

         section .data
constant_ten:        dd 10
float_result:      dd 0
temp_float:        dd 0

         section .text

         Enter 0
         Push_Regs ebx, ecx, edx

; neg_mantissa boolean in eax and neg_exponent in ebx.

         mov eax, [ebp + 16]
         mov ebx, [ebp + 12]

; Move fraction_cnt into ecx (this is the number of digits that I counted to the right
; of the decimal point when I converted the string into an integer). It is saved
; on the stack at offset 24.

         mov ecx, [ebp + 24]

; Push fraction onto the coprocessor stack. 
  
         fild dword [ebp + 28]

%ifdef DEBUG
push eax
Make_Local_Str temp_cf1_len, temp_cf1_str, 'ConstructFloat: fraction is %d', 10, 0
C_Sys_Call printf, 2, temp_cf1_str, [ebp + 28]
pop eax
%endif

; Put 1.0 on FP stack and multiply by 10 ecx times unless fraction is 0.

         cmp dword [ebp + 28], 0
         je cf_skip_fract_scale

         fld1

cf_next_mult1:

         fimul dword [constant_ten]

         loop cf_next_mult1

; Do st1/st0, which should make the fractional part a real fraction.

         fdivp st1

cf_skip_fract_scale:

; Load the whole number part.

         fild dword [ebp + 32]

; Add the fraction and whole number part and pop.

         faddp st1

; Invert if neg_mantissa is 1 (true)

         cmp eax, 1
         if e
            fchs
         endif

%ifdef DEBUG
push eax
fst dword [temp_float]
push dword [temp_float]
call PrintFloat
add esp, 4
pop eax
%endif

; Process the exponent... YOU NEED TO WRITE THIS PART OF THE CODE.


%ifdef DEBUG
push eax
push dword [edx]
call PrintFloat
add esp, 4
pop eax
%endif

         Pop_Regs ebx, ecx, edx
         Leave
         ret



;================================================================================
; Calling routine -- after the partitioning of the string into substrings and
; the conversion to integers.
;================================================================================

         ...
         push dword [whole_num]
         push dword [fraction]
         push dword [fraction_cnt]
         push dword [exponent]
         push dword [neg_mantissa]
         push dword [neg_exponent]
         mov ebx, [ebp + 8]
         push dword ebx
         call ConstructFloat
         add esp, 28
         ...
