;--------------------------------------------------------------------------------------------------------------
   ;this will out put floating point value to the screen

;--------------------------------------------------------------------------------------------------------------

  use16
  org  100h


  main:

    xor        ah,ah
    int        16h
    mov        di,ansStr

    finit			   ;resetting all registers and flags to their default values
    fld        [float1] 	   ;x


    call       fndNum



  .prnt:
    mov        al,24h
    cld
    stosb

    mov        dx,ansStr
    mov        ah,9h
    int        21h

  exitProg:
    xor        ah,ah
    int        16h
    mov        ax,4c00h
    int        21h









  fndNum:

  .rndAndSave:
    fld        st		   ;duplicate top register so	x,x

    mov        bx,0c00h 	   ;to change RC of the control word to truncate
    call       chgCnWd		   ;change RC of the control word
    frndint			   ;int x,x
    call       rvrtCnWd 	   ;revert to defalt value of control word
    ;fld	st		    ;int x,int x,x
    fbstp      [num]		   ;int x,x

  mkAnsStr:
    mov        si,num+9
    mov        cx,9
    mov        bx,0

 wrtSgn:
    std
    lodsb
    or	       al,al
    jns        .pstv

    mov        al,'-'
    cld
    stosb
    jmp        strLoop


  .pstv:
    mov        al,'+'
    cld
    stosb
    jmp        strLoop





  strLoop:
    cmp        cx,0
    jz	       .cmplt
    xor        ax,ax
    std
    lodsb

  .readNum1:
    mov        ah,al
    shr        al,4		      ;to get the first nibble in bcd data
    mov        bl,0

  .ckzeros:

    cmp        al,0
    jne        .storNum
    cmp        [charPostn],0
    jne        .storNum
    jmp        .ckNibble


  .storNum:
    inc        [charPostn]
    add        al,30h
    cld
    stosb

    jmp        .ckNibble

  .ckNibble:
    cmp        bl,0
    je	      .readNum2
    dec        cx
    jmp        strLoop

  .readNum2:
    mov        al,ah
    and        al,0fh		   ;get the second part of the bcd number
    mov        bl,1
    jmp        .ckzeros

  .cmplt:
    cmp        [charPostn],0
    jne        ..return
    mov        al,'0'
    cld
    stosb

  ..return:
    mov        [charPostn],0
    ret
 ;------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------
 chgCnWd:
    fstcw      [svSw]		  ;save control word
    fwait
    mov        ax,[svSw]
    or	       ax,0c00h 	     ;set RC bits to 1 1 and keep other bits
    xchg       ax,[svSw]
    fldcw      [svSw]		  ;set control word to truncate
    xchg       ax,[svSw]
    ret
;------------------------------------------------------------------------------------------------------------------

 rvrtCnWd:
    fldcw      [svSw]
    ret

;------------------------------------------------------------------------------------------------------------------



 ;---------------------------------------data------------------------------------------------------------------



 float1     dd	 4789640.889
 zeroval    dd	 0.0
 oneval     dd	 1
 tenval     dd	 10
 ;onetenth   dd   0.1
 svSw	    dw	 0
 ;adjexpo    dw   0
 ;adjexpo    db   0
 ;expVal     dw   0
 num	    dt	 0.0
 multi	    dd	 1000000000
 charPostn  db	 0
 ;loopnum    db   0
 ansStr     db	 10 dup (0)