Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

18 Bytes! Anyone can beat this? - No (Developers)

posted by cm(R) Homepage E-mail, Düsseldorf, Germany, 13.04.2009, 14:08

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:

Back to the forum
Board view  Mix view
15186 Postings in 1365 Threads, 250 registered users, 13 users online (0 registered, 13 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum