[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2004-11-20
Medium Priority
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

Expert Comment

ID: 12648340
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

rstaveley earned 320 total points
ID: 12648388
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 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