Re:Writing a self-modifying x86 factorial program
by idiocrat on Wednesday December 15, 2021 @05:25AM
(#29564041)
You do not need the "cmp ebx, ..." because "sub ebx, 1" already sets the zero flag.
Re:Writing a self-modifying x86 factorial program
by FastEatSlow on Wednesday December 15, 2021 @06:08AM
(#29564354)
Thanks, I forgot about that
Re:Writing a self-modifying x86 factorial program
by ghusbands on Wednesday December 15, 2021 @08:37AM
(#29565691)
Also, 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.
Re:Writing a self-modifying x86 factorial program
by FastEatSlow on Wednesday December 15, 2021 @11:47AM
(#29568375)
Thanks, I forgot about dec.
Re:Writing a self-modifying x86 factorial program
by FastEatSlow on Wednesday December 15, 2021 @05:50AM
(#29564216)
There was an edge case where when the input was 0x2, it returned 0x1, that was my quick way of handling that.
Re:Writing a self-modifying x86 factorial program
by unnouinceput on Wednesday December 15, 2021 @10:56AM
(#29567730)
Let'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
Re:Writing a self-modifying x86 factorial program
by jonsen on Wednesday December 15, 2021 @04:44AM
(#29563808)
> ; could exit at 1, but then it doesn't handle 0x2
Re:Writing a self-modifying x86 factorial program
by unnouinceput on Wednesday December 15, 2021 @10:51AM
(#29567644)
that's a comment for another variant. For this, at beginning, it could simply stop at 1
It's for me, because you can definitely do one less loop by modifying:
cmp ebx, 0
to
cmp ebx, 1