U E D R , A S I H C RSS

C/Assembly/Main

우선 기억 하는 것 복습.

~cpp 
int main(){ return; }

.globl main
        .type   main, @function
main:
        pushl   %ebp            // 현재의 명령어 Counter를 Stack에 저장함. 이 프로그램이 끝나면 stack에서 다시 꺼냄.
        movl    %esp, %ebp
        subl    $8, %esp        // 빈 스택 할당
        andl    $-16, %esp

        movl    $0, %eax        // eax = 0
        addl    $15, %eax       // eax = 15
        addl    $15, %eax       // eax = 15  11110(Bin)
        shrl    $4, %eax        // eax = 0xF0000001   11110000000000000000000000000001(bin)
        sall    $4, %eax        // eax = 0x1F         00000000000000000000000000011111(bin)

        subl    %eax, %esp

        movl    $0, %eax        // return 0;
        leave                   // 프로그램의 종료. stack에서 프로그램 시작 전의 명령어를 꺼내 %ebp에 집어 넣는 역할.
        ret                     // 프로그램이 종료.

push - ret
Windows OS가 아닌 DOS OS는 메모리의 관리를 Kernel(OS의 Core)이 아닌 Program에서 해주게 된다.
따라서 프로그램이 시작하고 나갈때에는 어디서 프로그램을 시작하고 끝냈는지 위치를 저장(push)하고 꼭 반환(leave)해야한다.
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:47
Processing time 0.0087 sec