print floating point number assembler 8086

Question!

I'm trying to print a floating point number using assembler 8086 and tasm!!! But i don't have any idea about how to do this. I have the number in a variable like this:

var dd 3.14235565212

Can you help me? Of curse the number is in the floating point format(you know IEEE 754 or something like that) thanks

By : A Zuniga


Answers

try this code.! but you have to declare variables which is an easy thing :)

`

    print_float     proc    near

    push    cx
    push    dx

    cmp     bott, 0
    jns     div_not_signed
    inc     bosig

    div_not_signed:
    cmp     upp, 0
    jns     upp_not_signed
    inc     upsig

    upp_not_signed:
    mov     cl, upsig
    sub     cl, bosig
    jz      positive
    neg     dx


    positive:
    cmp     ax, 0
    jne     checked         
    cmp     dx, 0
    jns     checked         
    push    dx
    mov     dl, '-'
    call    write_char      
    pop     dx
    checked:

    call    print_num

    cmp     dx, 0
    je      done

    push    dx

    mov     dl, '.'
    call    write_char
    pop     dx

    mov     cx, 5
    call    print_fraction
    done:
    pop     dx
    pop     cx
    ret
    print_float     endp





    print_fraction  proc    near
    push    ax
    push    dx
    next_fraction:

    cmp     cx, 0
    jz      end_rem
    dec     cx     


    cmp     dx, 0
    je      end_rem

    mov     ax, dx

    imul    ten2             

    idiv    bx              

    push    dx              
    mov     dx, ax
    cmp     dx, 0
    jns     not_sig
    neg     dx
    not_sig:
    add     dl, 30h         
    call    write_char      
    pop     dx

    jmp     next_fraction
    end_rem:
    pop     dx
    pop     ax
    ret
    print_fraction  endp




    print_numx      proc    near
    push    bx
    push    cx
    push    dx


    mov     cl, 1

    mov     bl, 100      


    cmp     al, 0
    jz      end_show

    begin_print:

    cmp     bl,0
    jz      end_show

    cmp     cl, 0
    je      calc

    cmp     al, bl
    jb      skip
    calc:
    xor     cl, cl 

    cbw
    div     bl      


    mov     dl, al
    add     dl, 30h    
    push    ax
    mov     ah, 02h
    int     21h
    pop     ax

    mov     al, ah  

    skip:
    push    ax
    mov     al, bl
    cbw
    div     ten    
    mov     bl, al
    pop     ax

    jmp     begin_print

    end_show:

    pop     dx
    pop     cx
    pop     bx
    ret
    print_numx      endp


    write_char      proc    near
    push    ax
    mov     ah, 02h
    int     21h
    pop     ax
    ret
    write_char      endp

`



Assuming you have a floating point unit available (pretty much a given, anymore), the easy way is to convert it to BCD format using FBSTP, then use the CPU to convert individual digits to ASCII/ISO/Unicode/whatever.



This video can help you solving your question :)
By: admin