[英]C struct to complete assembly code for function
我得到了以下代码框架:
typedef struct node {
_______________ x;
_______________ y;
struct node *next;
struct node *prev;
} node_t;
node_t n;
void func() {
node_t *m;
m = ______________________;
m->y /= 16;
return;
}
在IA-32 linux机器上生成的以下汇编代码:
func:
pushl %ebp
movl n+12,%eax
movl 16(%eax),%eax
movl %esp,%ebp
movl %ebp,%esp
shrw $4,8(%eax)
popl %ebp
ret
我需要填写上面的空白。 我确实相信,当我看着他的台词时:
m->y /= 16; and shrw $4,8(%eax)
这显然是node_t * m的第8个字节的右移。 所以我认为y之前有8个字节,所以x为8个字节长(双精度)。 另外,我认为结构“节点”的总大小来自
movl n+12, %eax
因为那是创建node_t * m的地方。 我只是不确定如何从该行确定其大小。
我也给了这个信息
还应注意,指针的大小和对齐方式为4个字节。
在32位模式下,指针为4字节,通常在4字节边界上对齐。 因此, n + 12
实际上正在加载%eax
& n.next
在其& n.next
。 例如,如果y
是 unsigned short
,则next
之前的结构中有2个字节的填充。
movl 16(%eax),%eax
以16个字节的偏移量解引用,得到: m = n.next->prev
struct node
{
double x; /* bytes: 0 .. 7 */
unsigned short y; /* bytes: 8 .. 9 */
/* bytes: 10 .. 11 */ /* (padding) */
struct node *next; /* bytes: 12 .. 15 */
struct node *prev; /* bytes: 16 .. 19 */
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.