next up previous contents
Next: Alpha Assembly ¾ð¾î ÇÁ·Î±×·¡¹ÖÇϱâ Up: GAS¸¦ ÀÌ¿ëÇÑ Alpha Assembly Previous: GAS¸¦ ÀÌ¿ëÇÑ Alpha Assembly

ÄÄÆÄÀÏ ¹æ¹ý

1.
Assembly ÄÚµå ÀÛ¼º

°¡Àå °£´ÜÈ÷ Assembly ¾ð¾î¸¦ ¸¸µå´Â ¹æ¹ýÀº ´ÙÀ½°ú °°ÀÌ C¾ð¾î¿¡¼­ Assembly ¾ð¾î¸¦ ÃßÃâÇØ ³»´Â ¹æ¹ýÀÌ´Ù.

´ÙÀ½Àº hello.c ÀÌ´Ù.

#include <stdio.h>

void main()
{

        printf("Hello World\n");

}

´ÙÀ½Àº C ¼Ò½º¿¡¼­ Assembler ¼Ò½º¸¦ ¾ò´Â ¹æ¹ýÀÌ´Ù.

% gcc -S hello.c

´ÙÀ½Àº ÀÌ·¸°Ô Çؼ­ ¾ò´Â Assembler ¼Ò½ºÀÌ´Ù.

        .file   1 "hello.c"
        .version        "01.01"
        .set noat
gcc2_compiled.:
__gnu_compiled_c:
.section        .rodata
        .align 3
$C32:
        .ascii "Hello World\12\0"
.text
        .align 3
        .globl main
        .ent main
main:
        ldgp $29,0($27)
main..ng:
        lda $30,-16($30)
        .frame $15,16,$26,0
        stq $26,0($30)
        stq $15,8($30)
        .mask 0x4008000,-16
        bis $30,$30,$15
        .prologue 1
        lda $16,$C32
        jsr $26,printf
        ldgp $29,0($26)
$33:
        bis $15,$15,$30
        ldq $26,0($30)
        ldq $15,8($30)
        addq $30,16,$30
        ret $31,($26),1
        .end main
        .ident  "GCC: (GNU) 2.7.2.1"

2.
GAS·Î ÄÄÆÄÀÏ Çϱâ

±×·¯¸é hello.s¶ó´Â assembly ÆÄÀÏÀÌ ¸¸µé¾î Áö´Âµ¥, ÀÌ°ÍÀ» GNU AssemblerÀÎ as·Î Object ÆÄÀÏÀ» ¸¸µç´Ù.

% as -o hello.obj hello.s

3.
½ÇÇà ÆÄÀÏ ¸¸µé±â

ÀÌÁ¦ Loader(ld)·Î ¶óÀ̺귯¸®¸¦ ÇÕÃÄ ½ÇÇà ÆÄÀÏÀ» ¸¸µé¾î ÁÖ¸é µÈ´Ù. À̶§ gcc·Î ÄÄÆÄÀÏÇØÁÖ¸é ÀÚµ¿À¸·Î ¸ðµç°ÍÀ» ¾Ë¾Æ¼­ ÇØÁØ´Ù.

% gcc -o hello hello.o

Assembly ÄÚµå ÀÛ¼º

°¡Àå °£´ÜÈ÷ Assembly ¾ð¾î¸¦ ¸¸µå´Â ¹æ¹ýÀº ´ÙÀ½°ú °°ÀÌ C¾ð¾î¿¡¼­ Assembly ¾ð¾î¸¦ ÃßÃâÇØ ³»´Â ¹æ¹ýÀÌ´Ù.

´ÙÀ½Àº hello.c ÀÌ´Ù.

#include <stdio.h>

void main()
{

        printf("Hello World\n");

}

´ÙÀ½Àº C ¼Ò½º¿¡¼­ Assembler ¼Ò½º¸¦ ¾ò´Â ¹æ¹ýÀÌ´Ù.

% gcc -S hello.c

´ÙÀ½Àº ÀÌ·¸°Ô Çؼ­ ¾ò´Â Assembler ¼Ò½ºÀÌ´Ù.

        .file   1 "hello.c"
        .version        "01.01"
        .set noat
gcc2_compiled.:
__gnu_compiled_c:
.section        .rodata
        .align 3
$C32:
        .ascii "Hello World\12\0"
.text
        .align 3
        .globl main
        .ent main
main:
        ldgp $29,0($27)
main..ng:
        lda $30,-16($30)
        .frame $15,16,$26,0
        stq $26,0($30)
        stq $15,8($30)
        .mask 0x4008000,-16
        bis $30,$30,$15
        .prologue 1
        lda $16,$C32
        jsr $26,printf
        ldgp $29,0($26)
$33:
        bis $15,$15,$30
        ldq $26,0($30)
        ldq $15,8($30)
        addq $30,16,$30
        ret $31,($26),1
        .end main
        .ident  "GCC: (GNU) 2.7.2.1"

GAS·Î ÄÄÆÄÀÏ Çϱâ

±×·¯¸é hello.s¶ó´Â assembly ÆÄÀÏÀÌ ¸¸µé¾î Áö´Âµ¥, ÀÌ°ÍÀ» GNU AssemblerÀÎ as·Î Object ÆÄÀÏÀ» ¸¸µç´Ù.

% as -o hello.obj hello.s

½ÇÇà ÆÄÀÏ ¸¸µé±â

ÀÌÁ¦ Loader(ld)·Î ¶óÀ̺귯¸®¸¦ ÇÕÃÄ ½ÇÇà ÆÄÀÏÀ» ¸¸µé¾î ÁÖ¸é µÈ´Ù. À̶§ gcc·Î ÄÄÆÄÀÏÇØÁÖ¸é ÀÚµ¿À¸·Î ¸ðµç°ÍÀ» ¾Ë¾Æ¼­ ÇØÁØ´Ù.

% gcc -o hello hello.o



Kwon Soon Son
1998-11-25