4 ms·
I did not understand how mov could be used for comparison. Is a register set to a certain value if the contents are already the same value when it's trying to w
by octocop 7y ago
I did not understand how mov could be used for comparison. Is a register set to a certain value if the contents are already the same value when it's trying to write?
- Liquid_Fire 7y agoIf you are comparing values X and Y, just write 0 to address X and 1 to address Y. Then read address X. If X and Y are equal, then you would have written first 0 and then 1 to the same address, so the final read would give you 1. If X and Y are different, then you would read back the 0 you wrote to address X.
- nexuist 7y agoIt took me a bit to grok this but I think I finally understand it. Super clever. Now, how would you do greater than / less than comparisons?
- magicalhippo 7y agoThe native and super inefficient way would be basically the same: write 1 to all addresses greater or equal to X, and 0 to all addresses less than X, then read from address Y and see what you end up with. Probably a more clever trick out there though.
- pjc50 7y agoNo, it's testing "did this MOV clobber address X or not." Put a guard value in address X. Write not-guard value to Y. Read X. If the value you just read wasn't the guard value, then Y was the same as X.