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

x
Solved

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

Posted on 2004-11-20
Medium Priority
702 Views
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
int 21h

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

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

output1:
mov dl, '1'
int 21h

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

LVL 8

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?
0

LVL 17

Accepted Solution

rstaveley earned 320 total points
ID: 12648388

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

0

## Featured Post

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