Mar 14, 2012 at 3:18 PM
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.
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.