How exactly do you convert a binary representation to its ASCII equivalent in assembly?

Posted on 2004-11-20
Last Modified: 2008-03-06
hello, i need some basic help. i'm trying to convert some binary numbers to decimal.  
i'm starting off with an array, and am trying to output each integer in the array, first its binary representation (which i'm not having trouble with), then its decimal
equivalent which has me scratching my head. i know i need to convert  the binary to ASCII but don't know how to do that. does anyone have any suggestions?

                      myArray dw 41,385,32767,256,1,600,7890,4096,3456,128,0,64

.code               ; start of code segment
main   proc          ; start procedure main
   mov   ax,seg myArray     ; mov to ax the segment address of 'myArray'
   mov   ds,ax          ; we now know where data is located in memory

; i have no problemt outputting the binary and realize i can just loop through the array with this code
   mov ah, 9
   mov dx, offset headerLine
   int 21h

   mov si, myArray + 0
   mov cx, 16
   mov ah, 2

     shl si, 1
     jc output1
     mov dl, '0'
     int 21h
     jmp nextStep

     mov dl, '1'
     int 21h

     loop output0
     mov ah, 6
     mov dl, 09h
     int 21h
; now i can't figure out how to turn the binary into ASCII
Question by:zeviddalop
    LVL 8

    Expert Comment

    Do you know how to convert on paper? If I gave the number 1010 binary could you convert this to ascii in decimal?

    Are you having trouble translating the problem to assembly or do you not know how to write the steps down on paper?
    LVL 17

    Accepted Solution

    How about

        number = value to be displayed
            digit = number mod 10 + '0'
            number = number div 10
            add digit to buffer
        while number > 0
        display buffer backwards

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    Convert from C to MIPS 14 1,331
    Cascading assemblies in .net libraries 4 351
    Buffer bomb nitro 1 4,258
    Address Range Confusion??? 4 370
    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now