4 ms·
The code in question: https://github.com/dspinellis/unix-history-repo/commit/389a475ba0445aa2816f84796786568a762a930d#diff-02d9990bf5c5bbe1b4473ff16783b30ec389f
by LukeShu 4y ago
The code in question: https://github.com/dspinellis/unix-history-repo/commit/389a475ba0445aa2816f84796786568a762a930d#diff-02d9990bf5c5bbe1b4473ff16783b30ec389fff3ffe30189990a48b6cbf72239R120 https://github.com/dspinellis/unix-history-repo/commit/389a4...
- pengaru 4y agoFunny. People here are conjecturing why one open codes the comparison instead of calling strcmp() presuming it's C when `ls` was written in assembler where calling a C function like strcmp() is far more onerous (and slow) vs. comparing to an immediate (cmpb, bne).
- ghayes 4y agoTo be fair, it doesn’t need to be strcmp since the target is known. It could simply check for a null terminator on the next byte or another dot followed by a null terminator. Surely a few more instructions, but not a complex subroutine call.
- draw_down 4y agoI don’t code in C too much but it seems like it would be pretty simple to check if the next index is a null byte.
- dsQTbR7Y5mRHnZv 4y agoAnd the modern reimplementation: https://github.com/coreutils/coreutils/blob/c7920f2/src/ls.c#L3138 https://github.com/coreutils/coreutils/blob/c7920f2/src/ls.c...
- efxhoy 4y agoNo wonder we call it code. I can read most programs and get a hunch of what's going on. With assembly like this I'm completely blank.
- 300bps 4y agoAssembly is actually pretty simple in that there just aren’t that many commands that are commonly used. https://en.m.wikipedia.org/wiki/X86_instruction_listings https://en.m.wikipedia.org/wiki/X86_instruction_listings For example, JSR becomes pretty self explanatory when you know it stands for Jump To Subroutine. The complexity is more in that you have to do many simple tasks on your own. It may take 50 lines of code in Assembly to do something that Java can do in one line of code.
- sundarurfriend 4y ago> The complexity is more in that you have to do many simple tasks on your own. And, especially while reading it, you have to keep track of a lot of the program state in your mind yourself, and that gets messy when you go beyond small, single-purpose chunks of code.
- ComputerGuru 4y agoAssembly is easy enough to write, but a nightmare to try to understand what someone else - or you - previously authored without great comments.