反汇编系列(六) switchcase

#include"stdio.h"
int function(int a,int b)
{
    int c=a+b;
    
    switch(c)
    {
        case 0:
            printf("c>0");
        case 1:
            printf("c>10&&c<100");
            break;
        default:
            printf("c>10&&c<100");
    }
    return c;
}
void main()
{
    function(1,2);
}

 


--- c:\users\wangchao\desktop\test\test\main.cpp -------------------------------
#include "stdio.h"
int function(int a,int b)
{
00EA2FE0 push ebp
00EA2FE1 mov ebp,esp
00EA2FE3 sub esp,0D0h
00EA2FE9 push ebx
00EA2FEA push esi
00EA2FEB push edi
00EA2FEC lea edi,[ebp-0D0h]
00EA2FF2 mov ecx,34h
00EA2FF7 mov eax,0CCCCCCCCh
00EA2FFC rep stos dword ptr es:[edi]
    int c=a+b;
00EA2FFE mov eax,dword ptr [a]
00EA3001 add eax,dword ptr [b]
00EA3004 mov dword ptr [c],eax
   
    switch(c)
00EA3007 mov eax,dword ptr [c]
00EA300A mov dword ptr [ebp-0D0h],eax
00EA3010 cmp dword ptr [ebp-0D0h],0
00EA3017 je function+44h (0EA3024h)
00EA3019 cmp dword ptr [ebp-0D0h],1
00EA3020 je function+5Bh (0EA303Bh)
00EA3022 jmp function+74h (0EA3054h)
    {
        case 0:
            printf("c>0");
00EA3024 mov esi,esp
00EA3026 push offset string "c>0" (0EA573Ch)
00EA302B call dword ptr [__imp__printf (0EA82B8h)]
00EA3031 add esp,4
00EA3034 cmp esi,esp
00EA3036 call @ILT+315(__RTC_CheckEsp) (0EA1140h)
        case 1:
            printf("c>10&&c<100");
00EA303B mov esi,esp
00EA303D push offset string "c>10&&c<100" (0EA57A0h)
00EA3042 call dword ptr [__imp__printf (0EA82B8h)]
00EA3048 add esp,4
00EA304B cmp esi,esp
00EA304D call @ILT+315(__RTC_CheckEsp) (0EA1140h)
            break;
00EA3052 jmp function+8Bh (0EA306Bh)
        default:
            printf("c>10&&c<100");
00EA3054 mov esi,esp
00EA3056 push offset string "c>10&&c<100" (0EA57A0h)
00EA305B call dword ptr [__imp__printf (0EA82B8h)]
00EA3061 add esp,4
00EA3064 cmp esi,esp
00EA3066 call @ILT+315(__RTC_CheckEsp) (0EA1140h)
    }
    return c;
00EA306B mov eax,dword ptr [c]
}
00EA306E pop edi
00EA306F pop esi
00EA3070 pop ebx
00EA3071 add esp,0D0h
00EA3077 cmp ebp,esp
00EA3079 call @ILT+315(__RTC_CheckEsp) (0EA1140h)
00EA307E mov esp,ebp
00EA3080 pop ebp

00EA3081 ret

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,您提供的是反汇编和C语言代码,无法直接给出switch语句的汇编。但是,我们可以根据您提供的信息,简单介绍一下switch语句的汇编实现方式。 在汇编语言中,switch语句通常被转换为一系列的条件分支指令,例如cmp和je指令。具体实现方式取决于编译器和处理器架构。在x86架构中,通常使用跳转表(jump table)来实现switch语句。跳转表是一个数组,其中每个元素都是一个指向代码的指针。当执行switch语句时,程序会计算出一个索引值,然后跳转到跳转表中对应的指针所指向的代码位置。 下面是一个简单的C语言switch语句的示例代码: ```c switch (x) { case 0: // do something break; case 1: // do something else break; default: // do something else break; } ``` 下面是该代码的汇编实现方式: ```assembly cmp eax, 0 je label1 cmp eax, 1 je label2 jmp default_label label1: ; code for case 0 jmp end_switch label2: ; code for case 1 jmp end_switch default_label: ; code for default case end_switch: ; code after switch statement ``` 在上面的汇编代码中,eax寄存器存储了switch语句的条件变量x的值。首先,程序会将eax的值与每个case语句中的常量进行比较,如果相等,则跳转到对应的标签(label1或label2)处执行相应的代码。如果没有匹配的case语句,则跳转到default_label处执行默认代码。最后,程序会跳转到end_switch处执行switch语句后面的代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值