Re: Hex to ascii
- From: Terje Mathisen <spamtrap@xxxxxxxxxx>
- Date: Thu, 14 Sep 2006 15:41:09 +0200
If you want any kind of fast binary to ascii conversion, you should take a close look at the code I posted here several years ago, and which AMD borrowed, without attribution :-(, for their optimization guide.
The key is that MUL is so much faster than DIV (and the related A* opcodes) that you can do quite a lot of funky stuff.
In the case of converting a binary value less than 100 to ascii, I'd look into using multiplication by ceil(65536/10):
; CX has binary value
mov ax,6554
mul cx
; At this point DX(DL) will contain the most significant digit!
mov al,10
mul dl
; If MUL is relatively slow, use LEA and/or shifts to do the same!
sub cx,ax
mov dh,cl
add dx,3030h
Yes, this is quite a bit larger than using AAM, but it is also 2 to 5 times faster on almost all x86 cpus.
In 32-bit mode the difference is even larger, the code AMD "borrowed" converts a full 32-bit unsigned integer to 10 decimal digits in less time than the cpu needs for a single DIV opcode! :-)
Terje
--
- <Terje.Mathisen@xxxxxxxxxxxxx>
"almost all programming can be viewed as an exercise in caching"
.
- Follow-Ups:
- Re: Hex to ascii
- From: Jean-François Michaud
- Re: Hex to ascii
- References:
- Hex to ascii
- From: Displacer
- Re: Hex to ascii
- From: Robert Redelmeier
- Re: Hex to ascii
- From: Rod Pemberton
- Hex to ascii
- Prev by Date: Re: 8088 LZSS+RLE decompression: Can this be improved?
- Next by Date: Is there nasm.el for Emacs?
- Previous by thread: Re: Hex to ascii
- Next by thread: Re: Hex to ascii
- Index(es):
Relevant Pages
|
|