Author | Message | Time |
---|---|---|
TheMinistered | I have some spare time on my hands, and I'm bored! I will show you how to make a jump forwards and backwards to a specified offset from the relative location. The opcode we will be using is JMP and the byte code will vary on how far you plan on jumping. Here are the selections! BYTE CODE: EB OPERAND: cb OPCODE: JMP DES: Rel8, jump short BYTE CODE: E9 OPERAND: cw OPCODE: JMP DES: Rel16, jump near BYTE CODE: E9 OPERAND: cd OPCODE: JMP DES: Rel32, jump near Lets assume that we are at offset 00401020 and we want to jump forward to offset 00401040. What we must do is calculate the relative offset from 00401020 to 00401040. To do this we take the address we want to jump to and subtract it from where we are, and this is our relative offset. Thus, 00401040 - 00401020 = 20 Once we have our relative offset we are ready to jump, you just pass the offset as the operand to the specified jump opcode. Now lets take the last scenario, only we want to jump backwards! I bet you are wondering how to do that? It is really quite simple, you can just make the number negative (NOT 20). [edit] There is another way to go about this, instead of subtracting like above you would do this, 00401020 - 00401040 = -20 If I messed up anywhere or made any mistakes, then by all means please correct me. For those of you who don't know, this is dword/nooblar on his new name. thank you! | April 11, 2003, 2:09 AM |
Kp | The source location for a jump is the first byte after the jump instruction itself. So if you wanted a jump instruction at 401020 to move you to 401040, you'd jump (401040 - 401022) = 1e bytes. This feature makes computing jump deltas a bit more complex, since different jump instructions are different lengths. | April 11, 2003, 4:57 AM |
iago | I already knew how to do that, but good work, still :-) Just do je/jne/jle/jl/jge/jg/etc. | April 11, 2003, 1:51 PM |