Hacker News new | ask | show | jobs
by pbsd 4571 days ago
Agree, AT&T syntax was just not designed for human reading. I doubt this is too optimized for size, since there are obvious tricks that it misses.

Another observation: the strlen code is incorrect, as it also counts the \0. We can fix this, and make the code 1 byte shorter (in glorious Intel syntax):

    lea esi, source        ; depends on source
    xor ecx, ecx           ; 2 bytes
    salc                   ; 1 byte
    cld                    ; 1 byte
    _back:
    scasb                  ; 1 byte 
    loopnz _back           ; 2 bytes
    not ecx                ; 2 bytes
2 comments

Thank you! About the time you wrote this, I discovered that the strlen code was incorrect in a different way as well, and then I went to sleep. Sort of embarrassing.
BTW, I've fixed the strlen code (although differently). I didn't know about SALC! That's a very clever way of zeroing AL.

I think at this point I might be able to get away with CLD since I never STD any more :)

Some of the obvious tricks it misses are probably because they're not obvious to me, while others may be just because I haven't gotten to them yet.

Your way is much cleaner; mine was just a size gimmick. I just can't resist it :)