c - A few assembly instructions -


could please me understand purpose of 2 assembly instructions in below ? (for more context, assembly + c code @ end). !

movzx  edx,byte ptr [edx+0xa] mov    byte ptr [eax+0xa],dl 

===================================

assembly code below:

push   ebp     mov    ebp,esp ,    esp,0xfffffff0 sub    esp,0x70 mov    eax,gs:0x14 mov    dword ptr [esp+0x6c],eax xor    eax,eax mov    edx,0x8048520 lea    eax,[esp+0x8] mov    ecx,dword ptr [edx] mov    dword ptr [eax],ecx mov    ecx,dword ptr [edx+0x4] mov    dword ptr [eax+0x4],ecx movzx  ecx,word ptr [edx+0x8] mov    word ptr [eax+0x8],cx movzx  edx,byte ptr [edx+0xa]    ; instruction 1 mov    byte ptr [eax+0xa],dl     ; instruction 2 mov    edx,dword ptr [esp+0x6c] xor    edx,dword ptr gs:0x14 je     804844d <main+0x49> call   8048320 <__stack_chk_fail@plt> leave   ret 

===================================

c source code below (without libraries inclusion):

int main() {     char str_a[100];         strcpy(str_a, "eeeeefffff"); } 

it inlined strcpy() call, code generator can tell 11 bytes need copied. string literal "eeeeefffff" has 10 characters, 1 0 terminator.

the code optimizer unrolled copy loop 4 moves, moving 4 + 4 + 2 + 1 bytes. needs done way because there no processor instruction moves 3 bytes. instructions asking copy 11th byte. using movzx bit overkill faster loading dl register.

observe changes in generated code when alter string. adding letter should unroll 3 moves, 4 + 4 + 4. when string gets long ought see fall memmove.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo