美文网首页
计算机本能会位运算. 加减乘除是通过位运算实现的

计算机本能会位运算. 加减乘除是通过位运算实现的

作者: onedam | 来源:发表于2021-02-27 13:54 被阅读0次

加法: 异或 然后 与运算 看是否都为 0

https://www.bilibili.com/video/BV1ff4y167LF?p=15&spm_id_from=pageDriver
非常好的 汇编教程 19节 课 24 要重点看.. call 和 return 指令 会影响堆栈. 并jmp跳转 ret 会把eip值
设置为堆栈顶里的32位值. intel 都是小端
https://www.bilibili.com/video/BV16U4y1s7QB

https://www.bilibili.com/video/BV16U4y1s7QB
这个没老师讲解,自己琢磨,搜资料 很困难. 去年看了几次,最后都是糊里糊涂. 一知半解.
这个是后续的指令集的讲解. good


int factorial(unsigned int i)
{
    if (i <= 1)
    {
        return 1;
    }
    return i * factorial(i - 1);
}

汇编

int factorial(unsigned int i)
{
00651CF0 55                   push        ebp  
00651CF1 8B EC                mov         ebp,esp  
00651CF3 81 EC C0 00 00 00    sub         esp,0C0h  
00651CF9 53                   push        ebx  
00651CFA 56                   push        esi  
00651CFB 57                   push        edi  
00651CFC 8D BD 40 FF FF FF    lea         edi,[ebp+FFFFFF40h]  
00651D02 B9 30 00 00 00       mov         ecx,30h  
00651D07 B8 CC CC CC CC       mov         eax,0CCCCCCCCh  
00651D0C F3 AB                rep stos    dword ptr es:[edi]  
00651D0E B9 29 E0 65 00       mov         ecx,65E029h  
00651D13 E8 58 F6 FF FF       call        00651370  
    if (i <= 1)
00651D18 83 7D 08 01          cmp         dword ptr [ebp+8],1  
00651D1C 77 07                ja          00651D25  
    {
        return 1;
00651D1E B8 01 00 00 00       mov         eax,1  
00651D23 EB 13                jmp         00651D38  
    }
    return i * factorial(i - 1);
00651D25 8B 45 08             mov         eax,dword ptr [ebp+8]  
00651D28 83 E8 01             sub         eax,1  
00651D2B 50                   push        eax  
00651D2C E8 F8 F6 FF FF       call        00651429  
00651D31 83 C4 04             add         esp,4  
00651D34 0F AF 45 08          imul        eax,dword ptr [ebp+8]  
}
00651D38 5F                   pop         edi  
00651D39 5E                   pop         esi  
00651D3A 5B                   pop         ebx  
00651D3B 81 C4 C0 00 00 00    add         esp,0C0h  
00651D41 3B EC                cmp         ebp,esp  
00651D43 E8 3D F5 FF FF       call        00651285  
00651D48 8B E5                mov         esp,ebp  
00651D4A 5D                   pop         ebp  
00651D4B C3                   ret  
image.png
int s() {
    return 0;
}

int s() {
00312470 55                   push        ebp  
00312471 8B EC                mov         ebp,esp  
00312473 81 EC C0 00 00 00    sub         esp,0C0h  
00312479 53                   push        ebx  
0031247A 56                   push        esi  
0031247B 57                   push        edi  
0031247C 8D BD 40 FF FF FF    lea         edi,[ebp+FFFFFF40h]  
00312482 B9 30 00 00 00       mov         ecx,30h  
00312487 B8 CC CC CC CC       mov         eax,0CCCCCCCCh  
0031248C F3 AB                rep stos    dword ptr es:[edi]  
0031248E B9 29 E0 31 00       mov         ecx,31E029h  
00312493 E8 D8 EE FF FF       call        00311370  
    return 0;
00312498 33 C0                xor         eax,eax  
}
0031249A 5F                   pop         edi  
0031249B 5E                   pop         esi  
0031249C 5B                   pop         ebx  
0031249D 81 C4 C0 00 00 00    add         esp,0C0h  
003124A3 3B EC                cmp         ebp,esp  
003124A5 E8 DB ED FF FF       call        00311285  
003124AA 8B E5                mov         esp,ebp  
003124AC 5D                   pop         ebp  
003124AD C3                   ret  
image.png image.png image.png image.png image.png image.png

相关文章

网友评论

      本文标题:计算机本能会位运算. 加减乘除是通过位运算实现的

      本文链接:https://www.haomeiwen.com/subject/ejrsfltx.html