将汇编代码放入宏中会在表达式错误中创建未知令牌

时间:2018-09-13 23:57:08

标签: macos assembly macros x86-64 att

因此,我在Assembly中创建了一个quine。并希望将部分代码放入宏中。但是,一旦这样做,我就会收到警告:

实例化:9:6:错误:表达式中的未知标记  mov,%rcx

Grace.s:28:1:注意:在宏实例化中 notmain(x)

这是带有宏的相关代码(出现错误)

.macro nomain
_main:
    push %rbp
    mov %rsp, %rbp
    lea name(%rip), %rdi
    lea write(%rip), %rsi
    call _fopen
    mov %rax, %rdi
    mov $10, %rdx
    mov $9, %rcx
    mov $34, %r8
    lea quine(%rip), %r9
    lea quine(%rip), %rsi
    call _fprintf
    leave
    ret
.endmacro

.data
quine: .string ".data%1$cquine: .string %3$c%4$s%3$c%1$cname: .string %3$cGrace_kid.s%3$c%1$cwrite: .string %3$cw%3$c%1$c%1$c.text%1$c.globl _main%1$c#main function%1$c_main:%1$c%2$cpush %%rbp%1$c%2$cmov %%rsp, %%rbp%1$c%2$clea name(%%rip), %%rdi%1$c%2$clea write(%%rip), %%rsi%1$c%2$ccall _fopen%1$c%2$cmov %%rax, %%rdi%1$c%2$cmov $10, %%rdx%1$c%2$cmov $9, %%rcx%1$c%2$cmov $34, %%r8%1$c%2$clea quine(%%rip), %%r9%1$c%2$clea quine(%%rip), %%rsi%1$c%2$ccall _fprintf%1$c%2$cleave%1$c%2$cret%1$c"
name: .string "Grace_kid.s"
write: .string "w"

.text
.globl _main
#main function
nomain

并且没有宏(Works)

.data
quine: .string ".data%1$cquine: .string %3$c%4$s%3$c%1$cname: .string %3$cGrace_kid.s%3$c%1$cwrite: .string %3$cw%3$c%1$c%1$c.text%1$c.globl _main%1$c#main function%1$c_main:%1$c%2$cpush %%rbp%1$c%2$cmov %%rsp, %%rbp%1$c%2$clea name(%%rip), %%rdi%1$c%2$clea write(%%rip), %%rsi%1$c%2$ccall _fopen%1$c%2$cmov %%rax, %%rdi%1$c%2$cmov $10, %%rdx%1$c%2$cmov $9, %%rcx%1$c%2$cmov $34, %%r8%1$c%2$clea quine(%%rip), %%r9%1$c%2$clea quine(%%rip), %%rsi%1$c%2$ccall _fprintf%1$c%2$cleave%1$c%2$cret%1$c"
name: .string "Grace_kid.s"
write: .string "w"

.text
.globl _main
#main function
_main:
    push %rbp
    mov %rsp, %rbp
    lea name(%rip), %rdi
    lea write(%rip), %rsi
    call _fopen
    mov %rax, %rdi
    mov $10, %rdx
    mov $9, %rcx
    mov $34, %r8
    lea quine(%rip), %r9
    lea quine(%rip), %rsi
    call _fprintf
    leave
    ret

0 个答案:

没有答案