There is a way to express a range check like this using only a single conditional jump:
sub eax, 20
cmp eax, 80
ja END
// do something
END: ret
This is a very common optimization trick when working with integer ranges. The initial subtract maps the range [20,100] to [0,80]; membership in that range is then be checked with a single unsigned comparison.
Note also that the same thing can be done in C:
unsigned int upperBound = 100;
unsigned int lowerBound = 20;
if (yourValue - lowerBound <= upperBound - lowerBound) {
// do something
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…