From: admin@nospicedham.127.0.0.1   
      
   On Sat, 15 May 2021 19:46:21 +0200   
   Terje Mathisen wrote:   
      
   > Kerr-Mudd, John wrote:   
   > > On Sat, 15 May 2021 11:21:43 +0100   
   > > "Kerr-Mudd, John" wrote:   
   > >   
   > >> On Fri, 14 May 2021 21:53:32 +0200   
   > >> Terje Mathisen wrote:   
   > >>   
   > >>> Robert Prins wrote:   
   > >>>> Is it possible to fit the conversion of a 16 bit signed integer to   
   > >>>> left-aligned ASCII without leading zeroes in just 65 bytes?   
   > >>>   
   > >>> Naively I would say yes: I assume you don't care about speed here?   
   > >>>   
   > >>> ;; AX has the value to be converted to ascii   
   > >> [code elided]   
   >   
      
   >   
   > I did consider printing each digit directly to the console, it probably   
   > would not have added much to the code size for an unsigned value, but   
   > getting the sign logic correct was much easier when using the STOSB buffer.   
   >   
   > xor cx,cx   
   > test ax,ax   
   > jge not_negative   
   >   
   > xchg ax,bx   
   > mov dl,'-' - '0'   
   > call print_char   
   > xchg ax,bx   
   > neg ax   
   >   
   > not_negative:   
   > mov bx,10   
   > next:   
   > ...   
   > test ax,ax   
   > jnz next   
   >   
   > print_digits:   
   > pop dx   
   > call print_char   
   > loop print_digits   
   > ret   
   >   
   > print_char:   
   > add dl,'0'   
   > mov ah,2   
   > int 21h   
   > ret   
      
      
   Dirty trick, saves a call/ret:   
      
    xor cx,cx   
    test ax,ax   
    jge not_negative   
      
    xchg ax,bx   
    mov dl,'-'   
    inc cx ; print once!   
    call print_char   
    xchg ax,bx   
    neg ax   
      
    not_negative:   
    mov bx,10   
    next:   
    ...   
    test ax,ax   
    jnz next   
      
    print_digits:   
    pop dx   
   print_*num*:   
    add dl,'0'   
    print_char:   
    mov ah,2   
    int 21h   
    loop print_digits   
    ret   
      
   --   
   Bah, and indeed Humbug.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|