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? HEX16 for 8086 | ROL (Developers)

posted by DOS386, 18.05.2009, 05:54
(edited by DOS386 on 18.05.2009, 06:09)

rr wrote:

> http://www.df.lth.se/%7Ejohn_e/gems/gem003a.html

:-)

mht wrote:

> You can still improve register usage. Use rotations on one
> register instead of shifts on two (4 rotations by 4 bits = no-op).

Thanks :-) You can't beat the 18 Bytes this way but indeed improve the "useful" variant :-)

> better cut-and-paste from there, instead of introducing additional
> noise

Welcome back to NOiSe ain't dead - the great C&P forum :confused:

use16

; HEX16 output conversion, 8086 compatible

; Input in AX | Trashes CX only !!!

;  9 instructions 18 Bytes vary bare, input in DX, trashes AX
; 10 instructions 18 Bytes very bare, input in AX, uses stack
; 10 instructions 19 Bytes very bare, input in AX, trashes DX, no stack
; 11 instructions 21 Bytes including call, input in AX, uses stack
; 14 instructions 24 Bytes including call, full register preservation and RET

hex16:
        push   cx

        mov    cx, 1028     ; "MOVNTQ CL, 4" + "MOVNTQ CH, 4"
h16l:
        rol    ax, cl       ; 8086 compatible, after 4 ROL's original back
        ; rol    dx, cl       ; 8086 compatible, after 4 ROL's original back
        ; mov    al, dl       ; AL <- DL , transfer 8 bits, only 4 are useful
        push   ax
        ; mov    dx, ax       ; Now both DX and AX are equal, XCHG not good
        and    al, $0F
        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 (+ DX or AX)
        pope   ax
        ; xchg   dx, ax       ; Restore trashed AX from DX, but now DX trash
        dec    ch           ; & No LOO'p on CH :-(
        jnz    short h16l   ; &

        pope   cx
        ret
        ;----

; Avoiding cryptic "DAS" (also preceding SBB, OTOH keep CMP) costs 3 Bytes:

        cmp    al, 10
        jb     short @f     ; OK, 0 ... 9
        add    al, 7        ; Fix for A ... F
@@:     add    al, 48

---
This is a LOGITECH mouse driver, but some software expect here
the following string:*** This is Copyright 1983 Microsoft ***

 

Complete thread:

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