18 Bytes! Anyone can beat this? - No (Developers)
My solution requires 34 bytes, but I think it's easier to understand than using das (or daa, see below).
disp_ax_hex: ; ax
xchg al,ah
call disp_al_hex ; display former ah
xchg al,ah ; and fall trough for al
disp_al_hex: ; al
push cx
mov cl,4
ror al,cl
call disp_al_lownibble_hex ; display former high-nibble
rol al,cl
pop cx
; and fall trough for low-nibble
disp_al_lownibble_hex:
push ax ; save ax for call return
and al,00001111b ; high nibble must be zero
add al,'0' ; if number is 0-9, now it's the correct character
cmp al,'9'
jna .decimalnum ; if we get decimal number with this, ok -->
add al,7 ; otherwise, add 7 and we are inside our alphabet
.decimalnum:
call disp_al
pop ax
retn
I think Henrik Haftmann's solution is good, too. It still requires 26 bytes. (Note that _ochr is actually the call to display the character in al, so it doesn't count. Note also that these macros aren't used as macros multiple times per program, they're used once, then they're called inside the program.)
macro _ochr ;Zeichenausgabe aus AL
ochr: push ax dx
mov dl,al
DOS 2
pop dx ax
ret
endm
macro _axhx ;Hexzahlausgabe, VR: AX,F
axhx: xchg al,ah
call ahex
xchg al,ah
ahex: push ax cx ;Werte erhalten
mov cl,4 ;oberes Nibble auf Bit 3...0
shr al,cl ; schieben
pop cx
call ahex1
pop ax
ahex1: and al,0fh
add al,90h ;Hex -> ASCII
daa
adc al,40h
daa
_ochr
endm
---
l
Complete thread:
- 18 Bytes !!! Anyone can beat this? HEX16 for 8086 - DOS386, 13.04.2009, 10:20 (Developers)
- 18 Bytes! Anyone can beat this? - No - ecm, 13.04.2009, 14:08
- 18 Bytes! Anyone can beat this? - No DAS - DOS386, 13.04.2009, 14:32
- 18 Bytes! Anyone can beat this? - No DAS - rr, 13.04.2009, 16:13
- 18 Bytes! Anyone can beat this? - No DAS - DOS386, 13.04.2009, 14:32
- 18 Bytes !!! Anyone can beat this? HEX16 for 8086 - mht, 13.04.2009, 16:04
- 18 Bytes !!! Anyone can beat this? HEX16 for 8086 | ROL - DOS386, 18.05.2009, 05:54
- 18 Bytes! Anyone can beat this? - No - ecm, 13.04.2009, 14:08