3 ms·
I don't understand what the author is talking about. He's writing as if people are familiar with this already or can read his mind (the #1 failure of all techni
by TwoBit 10y ago
I don't understand what the author is talking about. He's writing as if people are familiar with this already or can read his mind (the #1 failure of all technical writing). I say this as somebody who understands x86 assembly. What is the following trying to convey?
"For example, jmp $+1 encodes as EB 01 ?? where ?? is the one byte to be jumped over. If burning a register is an option, then mov al, imm8 (encoded as B0 ??) might be an alternative (that is, the byte being jumped over becomes the imm8 value)."
- tedunangst 10y agoYeah, it's a little opaque. I'll try to rephrase. You have some code, with an if and else. if (cond) X else Y. After that comes code Z. When you compile this, the compiler emits instructions to check the condition, and if it's zero, jump to the else. Otherwise it proceeds to run X. At the end of X, you need to add another jump over Y to Z. Otherwise you'd execute Y too. Having lots of little jumps in your code can slow things down (well, maybe, depending on CPU, etc., but stipulate that jumps are bad). So at the end of X, you have to have a jump over the length of Y. However, if Y is very short, like 1 or 4 bytes, you don't actually need to use a jump instruction. Instead, pretend the Y instruction is a constant, and load it into a register (and ignore it). The result is the CPU runs X, loads some ignored data into a register, then runs Z. No jumps.