代码之家  ›  专栏  ›  技术社区  ›  ArekBulski

“push”[重复]的操作数类型不匹配

  •  0
  • ArekBulski  · 技术社区  · 7 年前

    我需要有关使用汇编部件的C代码的帮助。GCC编译程序集时出现问题,错误:

    $ make
    gcc -Wall -g -std=c99 -pedantic   -c -o sthread.o sthread.c
    sthread.c: In function ‘sthread_create’:
    sthread.c:159:57: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
         t->context = __sthread_initialize_context(t->memory + DEFAULT_STACKSIZE, f, arg);
                                                             ^
    gcc -Wall -g -std=c99 -pedantic   -c -o queue.o queue.c
    as -g  -o glue.o glue.s
    glue.s: Assembler messages:
    glue.s:32: Error: operand type mismatch for `push'
    <wbudowane>: polecenia dla obiektu 'glue.o' nie powiodły się
    make: *** [glue.o] Błąd 1
    

    __sthread_switch:
        # preserve CPU state on the stack, with exception of stack pointer, instruction pointer first, reverse order
        pushq %rip  #line 32
        pushf
        pushq %rdi
        pushq %rsi
        pushq %rbp
        pushq %rbx
        pushq %rdx
        pushq %rcx
        pushq %rax
    
        # Call the high-level scheduler with the current context as an argument
        movq    %rsp, %rdi
        movq    scheduler_context, %rsp
        call    __sthread_scheduler
    
    2 回复  |  直到 7 年前
        1
  •  6
  •   Peter Cordes    7 年前

    具有 X86_64 你不能推 %rip

    如果你还需要做,你可以做

    leaq 0(%rip), %rax # Or any other GPR that is free
    pushq %rax 
    

    callq . + 5          # no label, hard-code instruction length
    # or
    callq 1f ;  1:       # with a local numbered label
    

    虽然我不确定 为什么? 你会想藏起来

        2
  •  1
  •   Peter Cordes    7 年前

    要推动RIP,只需执行 call

    call next_insn
    next_insn:
    

    所以跳跃部分 呼叫

    有趣的事实: call rel32=0 is a special case and doesn't unbalance the return address predictor stack call next_insn / pop eax 在32位模式下有用,相当于 lea (%rip), %rax .

    push 对于1个微熔合uop)的探地雷达 lea(%rip),%rax ; push %rax 可能效率更高。

    推荐文章