4 ms·
>>This is quite simple, if it needs explanation then this isn’t for you. It's for me, because you can definitely do one less loop by modifying: cmp ebx, 0 to
by unnouinceput 5y ago
>>This is quite simple, if it needs explanation then this isn’t for you.
It's for me, because you can definitely do one less loop by modifying:
cmp ebx, 0
to
cmp ebx, 1
- jonsen 5y ago> ; could exit at 1, but then it doesn't handle 0x2
- unnouinceput 5y agothat's a comment for another variant. For this, at beginning, it could simply stop at 1
- idiocrat 5y agoYou do not need the "cmp ebx, ..." because "sub ebx, 1" already sets the zero flag.
- FastEatSlow 5y agoThanks, I forgot about that
- FastEatSlow 5y agoThere was an edge case where when the input was 0x2, it returned 0x1, that was my quick way of handling that.
- unnouinceput 5y agoLet's see, step by step, if we put 2 in EAX what happens: Init: EBX = 2; EAX = 2; Loop: EBX = 1;//gets decremented CMP EBX, 1;//it's 1 so we exit Final result is 2. Sounds the edge case is not that of an edge after all
- ghusbands 5y agoAlso, if we're to be pedantic about the code across the article, if they used dec (directly on memory) rather than sub, in the self modifying code, they wouldn't need a load/sub/store sequence. The zero flag would still be appropriately modified.
- FastEatSlow 5y agoThanks, I forgot about dec.