2013-11-04 3 views
3

현재 어셈블리 언어에있는 매크로의 개념을 이해하려고합니다. 내 대학의 슬라이드는 다음과 같이 말합니다 :어셈블리의 매크로 (IA32, AT & T 구문)

# How to define a macro: 
.macro write string 
    movl string, %esi 
    call printstr 
.endm 

# How to use a macro: 
write aString 

그러나 이것은 나에게 적합하지 않습니다. 내 코드를 컴파일하려면 gcc을 사용하고 있습니다.

.data 
    msg: .string "The result is %d.\n" 

.text 
.global main 

.macro add_3 n 
    movl n, %eax 
    addl $3, %eax 
.endm 

main: 
    add_3 $39 
    pushl %eax 
    pushl $msg 
    call printf 
    popl %eax 
    popl %eax 
    movl $1, %eax 
    int $0x80 

나는 이것을 컴파일하려고, 내가받을 다음과 같은 오류 :

undefined reference to `n' 
정확히 내가 잘못 뭐하는 거지

?

+7

매크로 내부를 사용할 때 백 슬래시 인수 이름을 붙이는보십시오. 나는. 'movl \ n, % eax' – Michael

+0

실제로 작동합니다. 정말 고마워요! – lambdarookie

+0

어디에서 투표 하시겠습니까? – johnfound

답변

5

매크로 내에서 사용할 때 인수 이름 앞에 백 슬래시를 붙이십시오. 예를 들어

movl \n, %eax


출처 : Michael