[Asterisk-Dev] FW: asterisk/doc CODING-GUIDELINES,1.4,1.5

Paul Cadach paul at odt.east.telecom.kz
Wed Jan 19 06:07:08 MST 2005


Hi,

Jerris, Michael MI wrote:
> It would probably be more efficient to check just the first char of the
> string to see if it is 0 than to loop through the whole string to see if
> it is > 0 length.

Just expand your and Andrew's solution into assembler-like constructions - you will see you don't have any CPU saving on
additional condition.

Your code looks like next (saves xor <reg>,<reg> and inc <reg> for zero-length strings but looses movsb, or, and
conditional jump on non-zero strings):
    mov        esi,[esp-4]
    movsb    eax,[esi]
    or           eax,eax
    jz            _ret
    xor         eax,eax
    jmp        _loop2
loop:
    inc         eax
loop2:
    movsb    ebx,[esi]
    inc         esi
    or          ebx,ebx
    jnz         _loop
_ret:
    ret

Andrew's code looks like:
    mov        esi,[esp-4]
    xor         eax,eax
    jmp        _loop2
loop:
    inc         eax
loop2:
    movsb    ebx,[esi]
    inc         esi
    or          ebx,ebx
    jnz         _loop
_ret:
    ret

My code looks like (i'm not sure about sub eax,esi, if it isn't possible there is additional mov <reg>,<reg> reqired):
    mov        eax,[esp-4]
    mov        esi,eax
_loop:
    movsb    ebx,[esi]
    inc         esi
    or          ebx,ebx
    jnz         _loop
    sub        eax,esi
    dec        eax
    ret


WBR,
Paul.






More information about the asterisk-dev mailing list