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'
정확히 내가 잘못 뭐하는 거지 ?
매크로 내부를 사용할 때 백 슬래시 인수 이름을 붙이는보십시오. 나는. 'movl \ n, % eax' – Michael
실제로 작동합니다. 정말 고마워요! – lambdarookie
어디에서 투표 하시겠습니까? – johnfound