Using MOV
MOV = Move data

Okay... we are going to look at the first main instruction we learned last lesson: MOV, which is short for "move data". Actually it's a bit more like "copy data from here to there", as you will see.

Here is some code. Comments start with a semicolon (;), so any line of text after a semicolon will be there to explain what's happening with the code.
MOV EAX,0          ;store 0 into EAX
MOV ECX,FFFF0688   ;store FFFF0688 into ECX
MOV EDX,434        ;store 434 into EDX
MOV EAX,AA31       ;store AA31 into EAX, erasing the previous value of 0 we stored earlier.
As you can see, MOV can be used to put numbers inside of registers like EAX, ECX, and EDX.

MOV also works with register-to-register storage:
MOV EAX,200        ;store 200 into EAX
MOV ECX,EAX        ;store the number that EAX holds into ECX. Now ECX also holds 200.
This will NOT work:
MOV 49E6D0,60    ;store the number 60 into the number 49E6D0?
Storing a number into another number makes no sense. You can't put the number 2 inside of number 5. But you can put numbers in registers, because registers hold numbers!

However, this WILL work:
MOV DWORD [49E6D0],60   ;store the number 60 into the address 0049E6D0.
Aha. So square brackets can be used to show that you mean "address", not number. Why do we need to put DWORD? Because DWORD specifies the size of the destination of the number 60. We don't want any old 60. We want a 60 that takes up the space of a DWORD, or 4 bytes. That's written as 00000060. In this case, DWORD [49E6D0] defines a memory location.

You can think of an offset as essentially an address. RAM offsets are very interesting, because you can modify them on the fly when the game is running.

Here are some examples of offsets:

4047B0 = Beginning of the Polar star code.
404B30 = Beginning of the Fireball code.
42ABD0 = Beginning of the code for Grasstown's "Power Critter" enemy.
49E6D0 = RAM offset for Quote's max health.
49E6CC = RAM offset for Quote's current health.
49E6E8 = RAM offset for the amount of fuel that the booster currently has.

Wow! So offsets tell you the locations (addresses) of all the important stuff in Cave Story.

Where do you find these awesome offsets? You need to get the assembly compendium, which is basically a text file with lots of info. Search for "Noxid's Modding/Hacking Resources" on the CS Tribute Site forums or just see this thread (the first download links in the thread are the ones you want).

Now that you have downloaded the Assembly Compendium, let me tell you what it is.
Noxid created the compendium by gathering together a ton of assembly-know-how from various people. The compendium is an excellent resource for any CS assembly hacker. Much of it is a list of important offsets, so you should definitely look at it. If you didn't download the compendium at all, you're not going to get very far with your ASM hacking. It's that important.

49E6D0 is the RAM offset of Quote's maximum health in Cave Story. So, that means:
MOV DWORD [49E6D0],60   ;this is actually setting the player's max health to 60 (hex).
60 (hex) = 96 (decimal). So, if you run this line of code, you would see Quote's max health immediately jump to 96. The problem is: where do I put this line of code so that the game runs it? We'll discuss this in future lessons.

Previous Lesson: Instructions
Next Lesson: Pointers and Memory
Table of Contents