Beginner's Guide to Cavestory Assembly

Mar 14, 2012 at 3:18 PM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
Pronouns: he/him
That's wrong because pointers. move ecx, [ebp+8] sets the value of ecx to the memory at location ebp+8. The next instruction compares the value at ecx+64 to 2. What you're doing is comparing the value of ebp+72 to 2, regardless of what the value of ebp+8 was.

Accessing [ebp+8] can be optimized though, and the way I usually do it is to pick a certain register (let's say ECX) and designate that as "official entity pointer register", so at the beginning of your code and after every function call (and division, and any other time you might need to commandeer ecx) you set it to [ebp+8], and then any time you need to access an entity's attributes you use ecx.

ebp is the Extended Base Pointer, meaning it points to the base of the call stack. [ebp] and [ebp+4] are set by most every function call (I think the return location and previous stack frame, respectively?) and [ebp+8] is where the first argument to your functions occur, in this case I'm going to assume a pointer to an entity or bullet. So let's say ebp is 1280C0, which means ebp+8 is 1280C8. If the memory value at 1280C8 is 4C9320, then that is the value that goes into ecx. Afterwards ecx+64 would reference 4C9384, and the value at that location may or may not be 2.
ebp-4 and below is what is used for local variables, but usually you want to subtract a certain amount from ESP before MOV EBP, ESP or something I forget it's been a while.
 
Mar 19, 2012 at 4:15 AM
Senior Member
"Ha! Ha! Ha! Mega Man is no match for my Mimiga Man!"
Join Date: Jan 21, 2011
Location:
Posts: 249
More useful info on the registers: http://www.cs.virginia.edu/~evans/cs216/guides/x86.html
 
Mar 23, 2012 at 1:15 AM
Not anymore
"Run, rabbit run. Dig that hole, forget the sun."
Join Date: Jan 28, 2010
Location: Internet
Posts: 1369
Age: 34
Pronouns: he/him
Hey guys. Rising from the dead to tell you about the new version 2.00, which is about 90% complete.

In other news, who would like a website for this ASM stuff? Like a real one on the 'net? I'm questioning what I can squeeze out here.
 
Mar 29, 2012 at 1:02 PM
Junior Member
"It's dangerous to go alone!"
Join Date: Jan 27, 2012
Location:
Posts: 33
How were all of the offsets, variable functions and other things found out in the Cave Story code? It seems to me that going through every single thing would crash the program 99% of the times. It would also be really inefficient. So how was it done?
 
Mar 29, 2012 at 3:58 PM
In my body, in my head
Forum Moderator
"Life begins and ends with Nu."
Join Date: Aug 28, 2009
Location: The Purple Zone
Posts: 5998
Pronouns: he/him
By a combination of experimentation, pattern recognition and contextual evidence. Once you know a few, the meaning of others can be inferred by their use.
 
Jul 19, 2012 at 5:21 AM
Not anymore
"Run, rabbit run. Dig that hole, forget the sun."
Join Date: Jan 28, 2010
Location: Internet
Posts: 1369
Age: 34
Pronouns: he/him
Now there are audio files that you can listen to that complement the guide:

https://www.youtube.com/watch?v=uH4HzY2Xe9M
https://www.youtube.com/watch?v=16n-KBvv5Io
 
Back
Top