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,336 of 4,675    |
|    Terje Mathisen to Robert Prins    |
|    Re: ITOA in 65 bytes    |
|    14 May 21 21:53:32    |
      From: terje.mathisen@nospicedham.tmsw.no              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       ; Store the string to the buffer pointed to by DI               xor cx,cx ; Count how many digits we find        test ax,ax ; Positive?        jge next              ; Negative input value, so print a '-' sign        mov byte ptr [di],'-'        neg ax        inc di              next:        xor dx,dx        mov bx,10        div bx        push dx ; Remainder is the digit        inc cx        test ax,ax ; Is it zero yet?        jnz next              dump_digits:        pop ax        add al,'0'        stosb        loop dump_digits              That looks like 17 instructions, most of them two-byte, 5 one-byte and a       couple that are longer, so 32-35 bytes?              Terje              --       - |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca