18 Bytes !!! Anyone can beat this? HEX16 for 8086 (Developers)
Task: convert the value in DX (or some other register) into a 4-Bytes string representing the number in HEX using 8086 compatible instructions (no TSR this time, sorry  )
)
Solution by King Udo (31 Bytes):
output_hex:
; On Entry:
;      dx = 2 byte hex value
; On Exit:
;      None
        mov      cx,4
output_hex10:
        mov      al,dh
        push     cx
        mov      cl,4
        shr      al,cl
        pop      cx
        and      al,0fh
        cmp      al,09h         ; greater 0-9?
        jg       output_hex20
        add      al,30h
        jmp      output_hex30
output_hex20:
        add      al,37h
output_hex30:
        ; call onecharal
        push     cx
        mov      cl,4
        shl      dx,cl
        pop      cx
        loop     output_hex10
My solution (18 Bytes):
use16
; HEX16 output conversion, 8086 compatible
; Input in DX or AX | Trashes AX CX DX
;  9 instructions 18 Bytes vary bare input in DX
; 10 instructions 19 Bytes very bare input in AX
; 11 instructions 22 Bytes including call, input in AX
; 18 instructions 29 Bytes including call, full register preservation and RET
        push   ax
        push   cx
        push   dx
        xchg   dx, ax       ; DX <- AX | Later peek the 4-bit groups from DX
        mov    cx, 1028     ; "MOVNTQ CL, 4" + "MOVNTQ CH, 4"
@@:     mov    al, dh       ; AL <- DH | Move all 8 bits, only upper 4 useful
        shl    dx, cl       ; 8086 compatible
        shr    al, cl       ; 8086 compatible
        cmp    al, 10       ; Now must be and is AL<=15 | Decimal "10" !!!
        sbb    al, $69      ; Securely Bugged Backup
        das                 ; Digital Attack System | ASCII result in AL
        call   onecharal    ; Input in AL | Must preserve CX and DX, not AX
        dec    ch           ; & No LOO'p on CH 
        jnz    short @b     ; &
        pope   dx
        pope   cx
        pope   ax
        ret
        ;----
---
This is a LOGITECH mouse driver, but some software expect here
the following string:*** This is Copyright 1983 Microsoft ***
Complete thread:
- 18 Bytes !!! Anyone can beat this? HEX16 for 8086 - DOS386, 13.04.2009, 10:20 ![Open in board view [Board]](img/board_d.gif) ![Open in mix view [Mix]](img/mix_d.gif) - 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
 Board view
Board view Mix view
Mix view