Roy.Browning@f506.n106.z1.fidonet.org (Roy Browning) (07/30/89)
Dumb Compiler/Intelligent Programmer vs Smart Compiler/Programmer Below is code I pruned from a working program and its assembly dump. Mark Williams version 4.0.12 was used which is considered a DUMB compiler. There is a total of 60 instructions, can a SMART compiler reduce this number with the register definition removed? I would appreciate seeing such code produced and knowing the compiler capable of accomplishing it. The reason I'm making this argument is that there is a third option, a smart compiler that permits its defaults to be overridden by the programmer. A vote for Smart Compilers and Intelligent Programmers, Roy Browning enum { zero, one } constants; int tabs; char *outgoing, *buff_position; int expand = zero; void Registers() { register char *incoming, *outgoingg; char *last_char; last_char = incoming; incoming = buff_position; outgoingg = outgoing; if (!expand) { for ( ; incoming <= last_char; incoming++, outgoingg++) { if (*incoming == '\n' && *(incoming-one) != '\r') { *outgoingg++ = '\r'; *outgoingg = *incoming; } else { *outgoingg = *incoming; } } } else { for ( ; incoming <= last_char; incoming++, outgoingg++) { if (*incoming == '\n' && *(incoming-one) != '\r') { *outgoingg++ = '\r'; *outgoingg = *incoming; } else if (*incoming == '\t') { outgoing = outgoingg; ptabs(one); outgoingg = --outgoing; } else { *outgoingg = *incoming; } } } outgoing = outgoingg; buff_position = incoming--; } Registers_: push si push di push bp mov bp, sp push ax mov -2(bp), si mov si, buff_position_ mov di, outgoing_ cmp expand_, $0 jne L11 L5: cmp si, -2(bp) ja L8 cmpb (si), $10 jne L20003 cmpb -1(si), $13 je L20003 mov bx, di inc di movb (bx), $13 L20003: movb al, (si) cbw movb (di), al inc si inc di jmp L5 L11: cmp si, -2(bp) ja L8 cmpb (si), $10 jne L12 cmpb -1(si), $13 je L12 mov bx, di inc di movb (bx), $13 L20006: movb al, (si) cbw movb (di), al jmp L13 L12: cmpb (si), $9 jne L20006 mov outgoing_, di mov ax, $1 push ax call ptabs_ add sp, $2 dec outgoing_ mov ax, outgoing_ mov di, ax L13: inc si inc di jmp L11 L8: mov outgoing_, di mov ax, si dec si mov buff_position_, ax mov sp, bp pop bp pop di pop si ret