Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ascii Functions

Status
Not open for further replies.

ackka

Programmer
Sep 25, 1999
269
0
0
US
Hi, sort of a simple question does anyone know of a function that you can use on a 8086 that does....
say you have a varable, a single byte with the value 44 in hex
This is 68 in Decimal, how would i get the string 68 in ascii characters, for output etc.. I am pretty sure i can figure out a algrithm i just did not now if their was one already existing.....

thanks in advance....
ackka
ackka@mad.scientist.com
duke_wave.gif
Java is the Future
 
Hello,

If you don't want to use these, the basic theory is just to divide the number you have with 10, save the rest (if you print it, it will show in reverse) and divide the rest untill you are done.

Here is a routine to show an 8-bit number, with comments:

mov al,7bh ; To print: 123
notdone:
aam ; number/10 to al, rest to ah
push ax ; numbers to stack
and ah,ah ; all numbers known?
jz done
mov al,ah ; no, recursion
call notdone
done:
pop dx ; retreive number
add dl,30h ; convert to ASCII
mov ah,2 ; DOS: print character in DL
int 21h
ret

A routine for 32 bit:
mov ax,0 ; to print:655360
mov dx,0ah
mov bx,0ah ; divider
; start of math
notdon:
mov cx,ax ; store LSB
mov ax,dx ; calculate DX/BX
xor dx,dx
div bx
xchg ax,cx ; MSB to CX, LSB to AX
div bx ; calculate (65536*R+AX)
xchg dx,cx ; rest to CX,MSB to DX
; end of math
push cx ; number to stack
mov cx,dx ; all numbers known?
or cx,ax
jz done
call notdon ; recursion
; print numbers
pop dx
add dl,30h ; convert to ascii
mov ah,2 ; DOS: print character in DL
int 21h
ret

To print 16 bit numbers, just fill dx with 0 and ax with the number.

Wouter Dijkslag

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top