LunarSoul said:
Hmm...Seems like a waste of space. Unless it's to group types of ASM code together, like weapon shot code.
It's actually a really efficient and elegant method to go to different portions of the code. In items with ids, such as previously mentioned entities or weapons, there is bound to be a lot of checks as to which id or which state we are in, and how to proceed from there. A simple way to do this would look something like this:
Code:
cmp eax,0
jne A
...
A cmp eax,1
jne B
...
B cmp eax,2
jne C
...
Where you check whether this part of the code should be run, and if not, jump down to the next check. However, those jmps are more often then not going to be long or "absolute" jmps (as opposed to short/relative jmps) which take up (if I remember correctly) six bytes each. Coupled with the cmps, this has a best case scenario of s = 9*n (tual best case, w/ short jumps, is 5*n). The jmp table has one jmp, and then a table of possible locations, meaning s = 7 + 4*n. The implication of this is that if you have more than
ONE (7 if only short jumps) check(s), a jmp table will be more efficient. It is also obscenely easy to expand. If you think that you might increase the number of states later, just leave some nops at the end of the table and you can fill them in later. With the first method, you have to completely restructure the code each time.
WoodenRat said:
Yeah I ment I want to make an NPC generator.
I don't know how much assembly you know, Mr. Rat. The easiest method to do such a thing would be to hack into an already existing generator and just swap out the entity argument in the creation function. If you don't know where to begin with that, say why not and me/nox/whoever will walk you through it.