home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 4,356 of 4,675   
   Kerr-Mudd, John to Bonita Montero   
   Re: ITOA in 65 bytes   
   21 May 21 10:50:14   
   
   From: admin@nospicedham.127.0.0.1   
      
   On Fri, 21 May 2021 07:53:38 +0200   
   Bonita Montero  wrote:   
      
   > > As no specifications have been posted, I do have some code that outputs a   
   > > signed number using just 25 bytes.   
   > > The trick ?    Filling the buffer backwards (putting the sign at the end).   
   >   
   > Show the code !   
   >   
      
   Simple enough to re-invent I'd have thought.   
   Something like this? (untested)   
      
      
   ; 16bit num in ax (max +/-32k), di is output area. uses bx,dx   
      
            add di,6            ; end of display area (possibly 5 digits & sign)   
            test ax,ax          ; Is it positive?   
            jge NotNeg   
            mov byte [di],'-'   ; put minus sign   
            neg ax              ; show as positive   
   NotNeg:   
            mov bx,10           ; decimal   
   NextDigit:   
            xor dx,dx           ; clear for div   
            div bx              ; get digit in dl   
            add dl,'0'   
            dec di              ; backward   
            mov [di],dl         ; putc   
            test ax,ax          ; finished?   
            jnz NextDigit   
      
   ;di now points to output string with '-' at the end if negative   
      
      
      
   --   
   Bah, and indeed Humbug.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca