반응형

VS 에서 작성한 풀소스  1~100  까지의 숫자 중 짝수만을 더한 구문을


C언어와 asm 으로 작성



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
 

int main()
{
//일반적인 C언어 더하기 구문
    int total = 0;
    int i = 0;
    for (int i=0;i<=100;i+=2)
    {
        total += i;
    }
 
 
    total = 0;
 

//어셈으로 작성한 더하기 구문
    __asm 
    {
        pushad
 
        mov eax, 0
 
        LP:
 
        add eax, 2
 
        add total, eax
 
        cmp eax , 100
        jnge LP
 
        popad
    }
 
    std::cout << total << std::endl;
 
 
    return 0;
}
 
cs





VS, C언어 작성하여 생성된 asm


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
int total = 0;
 
 mov         dword ptr [total],0  
 
    int i = 0;
 
 mov         dword ptr [i],0  
 
    for (int i=0;i<=100;i+=2)
 
 mov         dword ptr [ebp-24h],0  
 
 jmp         main+48h (0F91FA8h)  
 
 mov         eax,dword ptr [ebp-24h]  
 
 add         eax,2  
 
 mov         dword ptr [ebp-24h],eax  
 
 cmp         dword ptr [ebp-24h],64h  
 
 jg          main+59h (0F91FB9h)  
 
    {
 
        total += i;
 
 mov         eax,dword ptr [total]  
 
 add         eax,dword ptr [ebp-24h]  
 
 mov         dword ptr [total],eax  
 
    }
 
 jmp         main+3Fh (0F91F9Fh)  
 
 
cs




직접 작성한 asm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
total = 0;
 
    __asm 
    {

        pushad

        mov eax, 0
 
        LP:

        add eax, 2
 
        add total, eax
 
        cmp eax , 100
 
        jnge LP
 
 
 
        popad
 
    }
cs




반응형

+ Recent posts