>> Delete No. 2344 article
No. 각각의 경우 어셈블리 코드

등록 2002-03-22 19:37:00     조회 5
이름 Cyberpunk Yun    

		<pre>안녕하세요..
 임시 변수를 쓰는 것과 xor 연산을 쓰는 것중 어느 것이 더 빠른지에
대해 의견이 많네요..
 사실 저도 어셈블리어에 대해서는 그다지 아는 게 없어서 자세히는
모르겠고요..
 다음은 2가지 경우의 c 언어 소스와 그것의 어셈블리 코드입니다.
어셈블리와 machine instruction에 대해서 잘 아시는 분은 리플 좀
부탁드립니다.
 1) xor 연산의 경우.
---------------------- C 코드-------------------------
void main(void) {
        int a = 5;
        int b = 10;
        a ^= b ^= a ^= b;
} 
 -------------------- assembly code--------------------
        .file   "xor.cpp"
        .version        "01.01"
gcc2_compiled.:
.text
        .align 4
.globl main
        .type    main,@function
main:
.LFB1:
        pushl   %ebp
.LCFI0:
        movl    %esp, %ebp
.LCFI1:
        subl    $8, %esp
.LCFI2:
        movl    $5, -4(%ebp)
        movl    $10, -8(%ebp)
        movl    -8(%ebp), %edx
        leal    -4(%ebp), %eax
        xorl    %edx, (%eax)
        movl    -4(%ebp), %edx
        leal    -8(%ebp), %eax
        xorl    %edx, (%eax)
        movl    -8(%ebp), %edx
        leal    -4(%ebp), %eax
        xorl    %edx, (%eax)
        movl    $0, %eax
        leave
        ret
.LFE1:
.Lfe1:
        .size    main,.Lfe1-main
        .ident  "GCC:(GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-98)"
 2) 임시 변수의 경우
---------------------- C 코드-------------------------
void main(void) {
        int a = 5;
        int b = 10;
        int c;
        c = a;
        a = b;
        b = c;
}
 -------------------- assembly code--------------------
        .file   "temp_var.cpp"
        .version        "01.01"
gcc2_compiled.:
.text
        .align 4
.globl main
        .type    main,@function
main:
.LFB1:
        pushl   %ebp
.LCFI0:
        movl    %esp, %ebp
.LCFI1:
        subl    $12, %esp
.LCFI2:
        movl    $5, -4(%ebp)
        movl    $10, -8(%ebp)
        movl    -4(%ebp), %eax
        movl    %eax, -12(%ebp)
        movl    -8(%ebp), %eax
        movl    %eax, -4(%ebp)
        movl    -12(%ebp), %eax
        movl    %eax, -8(%ebp)
        movl    $0, %eax
        leave
        ret
.LFE1:
.Lfe1:
        .size    main,.Lfe1-main
        .ident  "GCC:(GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-98)"
 감사합니다.
 </pre>--Unfortunately no one can be told what the Chaos Club is.
[관리자] 패스워드를 입력 하십시오. 답장이 존재하면 함께 삭제됩니다.[ 목록 | 이전 ]
패스워드:    

Copyleft 1999-2026 by JSBoard Open Project
Theme Designed by IDOO All right reserved