Author | Message | Time |
---|---|---|
iago | To start the ball rolling: [code].text:6FC01A00 sub_6FC01A00 proc near ; CODE XREF: .text:6FC01000p .text:6FC01A00 ; D2Net_10025p ... .text:6FC01A00 mov eax, Variable .text:6FC01A05 cmp eax, 1 .text:6FC01A08 jnz short loc_6FC01A0B .text:6FC01A0A retn .text:6FC01A0B ; --------------------------------------------------------------------------- .text:6FC01A0B .text:6FC01A0B loc_6FC01A0B: ; CODE XREF: sub_6FC01A00+8j .text:6FC01A0B xor ecx, ecx .text:6FC01A0D cmp eax, 2 .text:6FC01A10 setz cl .text:6FC01A13 mov eax, ecx .text:6FC01A15 retn .text:6FC01A15 sub_6FC01A00 endp [/code] This has two optimizations, the first one is more obvoius, though. The top half would be this: [code]if((eax = Variable) == false) return; // keeping in mind that return value is in eax[/code] Then in the second half, it compares it sets ecx to null, does the comparison, sets cl to 1, moves ecx to eax, then returns. I've seen this construct many times, and all it's really doing is, [code]if(eax == 2) return true;[/code] | February 22, 2004, 7:04 PM |
iago | hmm, I should add the most famous optimization: [code].text:6FC0132E ADC xor esi, esi[/code] is the same as, esi = 0. | February 29, 2004, 10:51 PM |
Arta | Still consider myself rather newb at this, so feel free to delete if wrong. [code] mov edx, eax dec eax test edx, edx jz return [/code] Equivalent to: [code] if(!eax) return -1; [/code] | March 1, 2004, 12:06 AM |
iago | [code]add edx, 0FFFFFFFCh[/code] For those of you who don't know, this has the same effect as subtracting 4 from edx. | March 8, 2004, 2:54 AM |
iago | Right Answer [code]mov edx, [some variable] movzx edx, dl[/code] Is the same as: [code]mov edx, [some variable] and edx, 0xFF[/code] (movZx stants for mov with Zero extend) On the other hand, this: [code]mov edx, [some variable] movsx edx, dl[/code] Will do the same thing if dl is positive, but will sign-extend if dl is negative, so: 7F will become 0000007F, and 80 will become FFFFFF80. (movsx means mov with Sign extend) Finally, [code]mov edx, [some variable] mov edx, dl[/code] Will have no affect because mov extends nothing and leaves the rest of the register intact. (Thanks to skywing for correcting me on this :)) | March 12, 2004, 3:26 AM |
iago | This is a very important pattern I see all the time: [code].text:1503AABB mov eax, esi .text:1503AABD neg eax .text:1503AABF sbb eax, eax .text:1503AAC1 mov ecx, edi .text:1503AAC3 neg ecx .text:1503AAC5 sbb ecx, ecx .text:1503AAC7 test ecx, eax ; Make sure both arguments are valid ....... [/code] this is the same as, if(esi != NULL && edi != NULL)..... | May 15, 2004, 1:51 AM |
TheMinistered | In C++, and many other languages, the compiler will generate the following code to access an item in an array: [code] mov eax, [arraybase+index*arraytypesize] [/code] arraybase is the pointer to the base of the array, index is the item in the array you are trying to retreive, and arraytypesize is the size of the type the array is declared as. | May 17, 2004, 1:21 AM |
iago | For some arithmatic: This C code: [code]int edx = 3; edx = edx * 2 + 5;[/code] will probably look like this: [code]mov edx, 3 lea edx, [5 + edx*2] [/code] lea's can be used for arithmatic. | May 17, 2004, 2:19 AM |