ASM code的说明 [英] Explanation of Asm code

查看:216
本文介绍了ASM code的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下GCC内联汇编从LuaJit的椰子库中提取。由它做什么解释线有人可以提供一个线?

The following GCC inline asm is taken from LuaJit's coco library. Can someone provide a line by line explanation of what it does?

static inline void coco_switch(coco_ctx from, coco_ctx to)
{
  __asm__ __volatile__ (
    "movl $1f, (%0)\n\t" 
    "movl %%esp, 4(%0)\n\t" 
    "movl %%ebp, 8(%0)\n\t"
    "movl 8(%1), %%ebp\n\t" 
    "movl 4(%1), %%esp\n\t" 
    "jmp *(%1)\n" "1:\n"
    : "+S" (from), "+D" (to) : : "eax", "ebx", "ecx", "edx", "memory", "cc");
}

感谢

推荐答案

我的ASM是一个有点模糊有关的细节,但我想我可以给你一个大致的了解。

My ASM is a bit fuzzy about the details, but I think I can give you a general idea.

ESP:堆栈指针,EBP:基指针

ESP: Stack pointer, EBP: Base pointer.

movl $1f, (%0)

移动值0x1F的参数为0(从)。

Move the value 0x1f into parameter 0 (from).

movl %%esp, 4(%0)

将寄存器的内容将ESP(从+ 4)。

Move the content of register ESP into (from + 4).

movl %%ebp, 8(%0)

移动寄存器EBP的内容为(从+ 8)。

Move the content of register EBP into (from + 8).

movl 8(%1), %%ebp

移动(到+ 8)的内容到寄存器EBP。

Move the content of (to + 8) into register EBP.

movl 4(%1), %%esp

移动(到+ 4)的内容到寄存器ESP。

Move the content of (to + 4) into register ESP.

jmp *(%1)

跳转到包含在地址(至)。

Jump to address contained in (to).

在1是一个跳转标签

+ S声明源(读)参数,+ D的目的地(写)参数。寄存器在声明的最后名单是揍列表中,可能是由ASM code修改寄存器列表,因此编译器可以采取措施来保持一致性(即不依赖于如ECX尚含相同的值之前)。

"+S" declares a "source" (read) parameter, "+D" a destination (write) parameter. The list of registers at the end of the statement is the "clobber" list, a list of registers possibly modified by the ASM code, so the compiler can take steps to maintain consistency (i.e., not relying on e.g. ECX still containing the same value as before).

我想这coco_ctx意思是可可语境。所以:函数保存在从结构中的当前栈帧,并设置堆栈帧到什么保存在到结构。基本上,它从当前函数跳转到另一个函数。

I guess that coco_ctx means "coco context". So: The function saves the current stack frame in the "from" structure, and sets the stack frame to what's saved in the "to" structure. Basically, it jumps from the current function into another function.

这篇关于ASM code的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆