Keep DAA! (was Re: 8086 bugs)
frustum at pacbell.net
Sat Dec 10 23:24:28 CST 2005
Chuck Guzis wrote:
> On 12/10/2005 at 12:09 PM Chuck Guzis wrote:
>>Code-cruncher quiz: Could this be done in 8088 code without DAA or a jump
>>or a reference to a table in memory using only a single 8-bit register?
> What? No takers?
> I'll post my solution tomorrow if no one beats me to it. Uses only AL (or
> A) register, no jumps, no tables and will work on x80 and x86.
; convert a nibble in A to an ascii hex character using only
; a single register, no DAA, no branches, ; and no tables.
; the crux of it is to drive a wedge between the values 0-9
; and A-F. this is done by adding the right amount to always
; generate a carry for the higher group of numbers, then do
; an "adi 0" to increment only the higher numbers.
; we need to wedge them apart 7 times to account for the
; ascii difference between '9'+1 (0x3A) and 'A' (0x41).
ani 15 ; isolate lowest nibble
; wedge step 1
adi 246 ; 0-9 are 246-255 with cy=0
; A-F are 0-5 with cy=1
adc 0 ; A-F are now 1-6
; wedge step 2
sui 246 ; 0-9 are 0-9 again with cy=0
; A-F are now 11-16 with cy=1
adc 0 ; 0-9 are 0-9; A-F are now 12-17
; wedge step 3
; wedge step 4
; wedge step 5
; wedge step 6
; wedge step 7
; convert to ascii
More information about the cctalk