flat assembler
Message board for the users of flat assembler.

Index > Main > PrintHex16 size optimizations?

Author
Thread Post new topic Reply to topic
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I am trying to make 16bit hex output very small.
So far i have eliminated hex-char table for size.
Maybe you have a trick for very small version?
This is intended for a 16bit size critical demo.

My code so far (22 bytes)
Code:
        ; ES:DI -> Video memory
        ; DX = Register to print
        ; AH = Color attribute

PrintHex16:
        mov     cx,4
.cycle: rol     dx,4
        mov     al,dl
        and     al,0Fh
        cmp     al,9
        jle     .nohex
        add     al,'A'-'9'-1
.nohex: add     al,'0'
        stosw
        loop    .cycle
        ret

        ; Trashed AL,CX,DX,DI
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 20 Mar 2010, 12:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17352
Location: In your JS exploiting you and your system
revolution
19 bytes:
Code:
PrintHex16:
     mov     cx,4
.cycle: rol dx,4
        mov     al,dl
       and     al,0Fh
      cmp     al,10
       sbb     al,069h
     das
 stosw
       loop    .cycle
      ret    
Post 20 Mar 2010, 13:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7740
Location: Kraków, Poland
Tomasz Grysztar
The SBB+DAS trick is already widely known on this forum, you can strip a few bytes with it.

EDIT: Oh, revolution was first with it. Smile
Post 20 Mar 2010, 13:07
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Cool, i was unaware of this method (i searched 4 a while)
I have been searching/pondering this for about 2 hours.
I had SBB in my back pocket but wasnt enough by itself.
I figured i could spend the rest of my life theorizing it
or i could just ask someone with more brains than me.
Hey, at least im only a few bytes behind the times, right?
Now i go read about this DAS instruction.
Thanks for help Smile
Post 20 Mar 2010, 13:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17352
Location: In your JS exploiting you and your system
revolution
I pwned Tomasz. Twisted Evil
Post 20 Mar 2010, 13:34
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
revolution wrote:
19 bytes:
Code:
PrintHex16:
.cycle: rol   dx,4
    


NOT 8086-compatible, better code: http://board.flatassembler.net/topic.php?t=9738 http://www.bttr-software.de/forum/forum_entry.php?id=6631

Quote:
I pwned Tomasz.


I pwned revolution.
Post 20 Mar 2010, 13:55
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
DOS386 wrote:
NOT 8086-compatible
Is there anyone who still uses 8086?
Post 21 Mar 2010, 08:35
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Fanael wrote:
DOS386 wrote:
NOT 8086-compatible
Is there anyone who still uses 8086?


Post 23 Mar 2010, 15:40
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
WARNING: old thread

rugxulo wrote:
Wolfenstein 3D for 8086 url=http://www.lootube.com/watch?v=5f7gW5X24ao


All what we need is a thing allowing to watch LooTubeFlashCrap on 8086 Wink
Post 10 May 2010, 09:50
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
Code:
        ;;dedicated to DOS386 a funny man
        and     al,$0f   ;prepare for DAA
        add     al,'0'   ;$00..$0f->'0'..'?' -> (AL<$100)&(CF=0) -> DAA.2nd_if with +$60 skept
        daa              ;if (AL and $0f > 9)|(AF=1(never TRUE)){ADD AL,$06}
        cmp     al,'A'-1 ;if $06 was not added
        sbb     al,-1    ;do nothing
        ;;               ;hope more polite then DAS
    
Post 29 Jul 2010, 17:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.