【发布时间】:2018-11-02 00:02:52
【问题描述】:
我需要有关使用 ASSEMBLY 部件的 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
【问题讨论】:
-
相关:You cannot access the instruction pointer directly。你想达到什么目的?为什么需要访问 RIP?有关访问 RIP 的替代方法,请参阅链接的问题。
-
rip不是通用寄存器,也没有专用的push rip指令。 -
您通常会在
call指令中获得相当于push rip的内容。进入函数时,调用者的rip已经保存在栈上,