Arrays AT&;气体组件
我正在为C的一个子集构建编译器,现在我正在处理数组。假设我有以下几点:Arrays AT&;气体组件,arrays,assembly,gnu-assembler,att,Arrays,Assembly,Gnu Assembler,Att,我正在为C的一个子集构建编译器,现在我正在处理数组。假设我有以下几点: int main() { int x[3]; x[0] = 1; x[1] = 3; x[2] = 4; } 在装配中,附件如下所示: movl $1, -12(%ebp) movl $3, -8(%ebp) movl $4, -4(%ebp) movl $1, %ebx movl $5, -12(%ebp, %ebx, 4) 到目前为止,一切顺利。现在,如果我想访问存
int main() {
int x[3];
x[0] = 1;
x[1] = 3;
x[2] = 4;
}
在装配中,附件如下所示:
movl $1, -12(%ebp)
movl $3, -8(%ebp)
movl $4, -4(%ebp)
movl $1, %ebx
movl $5, -12(%ebp, %ebx, 4)
到目前为止,一切顺利。现在,如果我想访问存储在%ebx
中的任意位置,我应该怎么做?我一直在读,但我不太懂语法
我尝试了以下方法,但似乎不起作用:
# Suppose I want to do x[1] = 5
movl $1, %ebx
movl $5, -4(%ebp, %ebx, 4)
我遗漏了什么?问题是数组的基不是-4(%ebp)
,而是-12(%ebp)
(因为第一个项目就是放在那里的),所以索引应该是这样的:
movl $1, -12(%ebp)
movl $3, -8(%ebp)
movl $4, -4(%ebp)
movl $1, %ebx
movl $5, -12(%ebp, %ebx, 4)
问题在于,数组的基不是-4(%ebp)
,而是-12(%ebp)
(因为第一个项就是放在那里的),所以索引应该如下所示:
movl $1, -12(%ebp)
movl $3, -8(%ebp)
movl $4, -4(%ebp)
movl $1, %ebx
movl $5, -12(%ebp, %ebx, 4)