2013-05-27 2 views
2

학교 프로젝트 용 Mac (10.7)에서 .asm 파일을 실행하려고합니다. 그러나 나는 그것을 실제로 실행하는 방법을 이해하는 것처럼 보일 수 없다. 나는 터미널에서 그것을 실행할 수 있지만 어떻게?Mac에서 asm 파일을 어떻게 실행합니까?

실제로 .asm 파일을 실행하려면 xcode를 사용해야합니까? 아니면 어셈블리 코드를 수동으로 다른 형식으로 변환해야합니까?

참고로 내가 실행하는 데 노력하고있어 프로그램은

# ************************************************************************ 
# * Program name : sieve * 
# * Description : this program prints all the prime numbers below 1000 * 
# ************************************************************************ 
.bss 
NUMBERS: .skip 1000 # memory space for the number table 
.text 
formatstr: .asciz "%d\n" # format string for number printing 
.global main 
# ************************************************************************ 
# * Subroutine : main * 
# * Description : application entry point * 
# ************************************************************************ 
    main: movl %esp, %ebp # initialize the base pointer 
    # Initialize the number table: 
    movl $0, %eax # initialize 'i' to 0. 
    loop1: movb $1, NUMBERS(%eax) # set number table entry 'i' to 'true' 
    incl %eax # increment 'i' 
    cmpl $1000, %eax # while 'i' < 1000 
    jl loop1 # go to start of loop1 
    # The sieve algorithm: 
    pushl $2 # initialize 'number' to 2 on stack 
    loop2: movl -4(%ebp), %eax # load 'number' into a register 
    cmpb $1, NUMBERS(%eax) # compare NUMBERS[number] to '1' 
    jne lp2end # if not equal, jump to end of loop 2 
    pushl $formatstr # push the format string for printing 
    call printf # print the number 
    addl $4, %esp # pop the format string 
    movl -4(%ebp), %eax # 'multiple' := 'number' 
    shl $1, %eax # multiply 'multiple' by 2 
    loop3: cmp $1000, %eax # compare 'multiple' to 1000 
    jge lp2end # goto end of loop2 if greater/equal 
    movb $0, NUMBERS(%eax) # set number table entry to 'false' 
    addl -4(%ebp), %eax # add another 'number' to 'multiple' 
    jmp loop3 # jump to the beginning of loop 3 
    lp2end: movl -4(%ebp), %eax # load 'number' into a register 
    incl %eax # increment 'number' by one 
    movl %eax, -4(%ebp) # store 'number' on the stack 
    cmpl $1000, %eax # compare 'number' to 1000 
    jl loop2 # if smaller, repeat loop2 
    end: movl $0,(%esp) # push program exit code 
    call exit # exit the program 
+1

질문은 아주 - 아주 무서운합니다. –

+2

[공간에 들어가기 전에 우주선을 켜는 법을 알고 있기를 바랍니다.] (http://en.wikipedia.org/wiki/Assembler) –

+1

Mac이란 무엇입니까? ;-) – ady

답변

1

구축하고 Mac에서 터미널 응용 프로그램 내에서, 즉 명령 줄에서이 작업을 실행 sieve.S에 파일을 저장하는 것입니다 예를 들면 다음과 같습니다 :

$ clang -m32 -g sieve.S -o sieve 
$ ./sieve 
2 
3 
5 
<...> 

나는 Xcode에서 이것을 어떻게 구축해야할지 모르겠다. 빈 프로젝트를 만들고 소스 파일로 sieve.S을 추가하면됩니다.

관련 문제