简体   繁体   English

一些组装说明

[英]A few assembly instructions

Could you please help me understand the purpose of the two assembly instructions in below ? 能否请您帮助我了解以下两个组装说明的目的? (for more context, assembly + C code at the end). (有关更多上下文,请在末尾使用汇编+ C代码)。 Thanks ! 谢谢 !

movzx  edx,BYTE PTR [edx+0xa]
mov    BYTE PTR [eax+0xa],dl

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

Assembly code below: 汇编代码如下:

push   ebp    
mov    ebp,esp
and    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): 下面的C源代码(不包含库):

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

It inlined the strcpy() call, the code generator can tell that 11 bytes need to be copied. 它内联了strcpy()调用,代码生成器可以告诉您需要复制11个字节。 The string literal "eeeeefffff" has 10 characters, one extra for the zero terminator. 字符串文字“ eeeeefffff”有10个字符,零终止符额外一个。

The code optimizer unrolled the copy loop to 4 moves, moving 4 + 4 + 2 + 1 bytes. 代码优化器将复制循环展开到4个移动,移动4 + 4 + 2 + 1字节。 It needs to be done this way because there is no processor instruction that moves 3 bytes. 因为没有处理器指令移动3个字节,所以需要这样做。 The instructions you are asking about copy the 11th byte. 您询问的有关复制第11个字节的指令。 Using movzx is a bit overkill but it is probably faster than loading the DL register. 使用movzx有点过大,但它可能比加载DL寄存器更快。

Observe the changes in the generated code when you alter the string. 更改字符串时,请注意生成的代码中的更改。 Adding an extra letter should unroll to 3 moves, 4 + 4 + 4. When the string gets too long you ought to see it fall back to something like memmove. 添加一个额外的字母应该展开3个动作,即4 + 4 +4。当字符串过长时,您应该看到它回落到像记忆之类的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM