Hi whoever is reading!
This document is all about learning ASM also known as Assembly. This will be a
basic guide going over the basic opcodes like mov, cmp, jmp and other stuff like
that.
Im your "host" Stix here writing this so yea... Let's start shall we?
First things first lets learn some easy opcodes. If you ever looked inside a script
you may have seen the following commands:
- mov
- cmp
- jne
- jmp
- sub
Right now they dont make any sense right? Well let me explain what they do and what
they mean.
1) mov
mov means move. We use mov when we need to move values around.
mov eax,6 - this opcode moves the value (6 in this case) into the register.
Registers are small storage location in your CPU. Basically these little fellas
store information.
In the case of the line above eax will store the value of 6.
Be careful with values can be decimal or hexadecimal.
51 (hexadecimal value) and #51 (decimal value) are NOT the same thing.
Something to note here is that decimal values can be converted to hexadecimal
values.
Using the example above #51 converts into 33.
The decimal to hexa decimal conversion. You take 51 and divide it by 16, that
equals 3 with a remainder of 3 which means the rightmost number is 3. Do this again
for the answer which was 3 so 3 devided 16 is 0 with a remainder of 3 which means
#51 which is decimal 51 is equal to hexadecimal 33.
Going back to the original line I was explaining, if we write mov eax,6 then eax =
6.
Let's go to the next one now.
One last thing i should mention is that when you use mov whatever value was in the
register before gets replaced.
So keep that in mind
2) sub
sub stands for subtract. We use sub when we want to subtract a value from a
register.
Example:
mov eax,6
sub eax,3
eax = 3
What happened here was we gave eax the value of 6 then subtracted 3 from it so 6 -
3 = 3 which means eax is now equal to 3.
If you payed any attention in math class or you are not a 3 year old you should
know basic math...
3) add
I think you get what add stands for. We use add when we wanna add a value from a
register.
Example:
mov eax,6
add eax,5
eax = #11/B
What happened here was we gave eax the value of 6 then added 5 from it so 6 + 5 =
11 which means eax is now equal to #11/B.
It's just the opposite of sub.
Problem:
(If you can solve this simple problem Ayban gave me while i was learning then you
can move on to the next opcodes. If not then idk. go to college or smth.)
add eax,2
mov eax,#51
sub eax,3
eax = ?
If you managed to solve that then good job! If you didnt then uhh, tough luck
buddy. Maybe try to go back to school.
Anyways, we should probably move on to the actual interesting stuff (at least more
interesting thand adding and subtracting values)
4) cmp
cmp means compare. We use cmp when we need to compare two values.
eax = 6
cmp eax,#10/A
This line will compare the value of eax which is 6 with the value of #10/A. From
here we can use opcodes like jne or je.
So to use cmp well we need to learn about...
5) jne and je
jne and je are opcodes that decide what to do with cmp outputs. Basically if the
compared values are equal, je which stands for jump if equal will jump to the
specified label.
In the case of Cheat engine every script will already have some labels made when
using the code injection template those being:
-returnhere
-originalcode
-exit
So if we have something like:
eax = 4
cmp eax,4
je originalcode
Since eax = 4 and 4 = 4 is true then je which stands for jump id equal will jump to
the originalcode label in the script and execute the code there instead of the code
after the je line.
In the case of jne its the opposite. jne is for when the compared output is false.
jne stands for jump if not equal.
So if we have:
eax = 51
cmp eax,4
jne originalcode
The script will jump to the originalcode label because the comoared values are not
equal.
This kind of opcodes are used most frequently when checking for plant or zombie ids
in scripts. Which looks something like this:
cmp [ebp+24],2E
jne exit
This compares the pointer of plants which in this case is [ebp+24] with the id of
2E which is spikeroks id.
If its not true, which would mean its another plant instead of spikeweed then it
will jump to the originalcode.
The easiest way to explain why you need this is to make lets say the snowpea slow
effect only apply to spikeweed. If we wouldnt do this any plant would have this.
Showing this example brings me to the next point(er).
6) pointers
This is where shit gets real and you need to start reading code. To determine the
pointer of plants lets say theres no fullproof method. This will depend on the
inject point of your script. To determine the pointer of plants you will need to
look at how its used in the code nearby. So if you see anything like [epx+24] it
might be either the pointer of plants or zombies depending of how its used. This is
kinda hard to explain but it becomes easier to determine with more experience
coding. Dont forget you can always ask for help from better scripters.
7) pushadd and popad
These are pretty more simple than the last stuff. Pushadd will preserve all the
registers at the time of the line.
Popad will put them back into the script. In the words of Ayban "useful if u dont
want to mes s up something".
Idk what else to say abot these so...
8) calls
If you made it here congrats. This is the final opcode you will need to know if you
wanna be able to make a simple script.
For short calls are just jumping to a certain area and returning after a set of
instructions.
For a longer explanation basically letssay you wanna call in the chill effect of
snowpea.
In the M.A. modding doc you will find the 5309C6 address under the effects section.
Go to the address in memory view inside of Cheat Engine. There should be some calls
nearby.
If you scroll down you should find call PlantsVsZombies.exe+12F050. You can just
paste this in your script.
There is more stuff to explain, im sure of it but this not so short file should be
able to help people whowanna get into asm but dont know where to start. If you dont
get it first try dont worry, no one did. Just dont give up because if you do, you
will never learn.
I am Stix and i wanna thank Ayban for helping me with some info for this file and
Bayant for helping me make my first script. You guys are awesome and im glad i had
the oportunity to learn from you two.
Anyways. Thats it. This is the end. One thing. If you wanna know the correct answer
for the question up there was 48.
But yea. That's it from me. Stay safe and keep modding! Adios.