[英]Translate from high-level language to IA-32
Can someone please translate this high-level code into IA-32 assembly without using any global variables? 有人可以在不使用任何全局变量的情况下,将此高级代码转换为IA-32程序集吗? I just need it as an example for other work I have to do.
我只需要它作为我要做的其他工作的示例。 Thanks.
谢谢。 Integers are 32-bit and chars are 8-bit.
整数是32位,而char是8位。
class MyString{
char buff[100];
int len;
void deleteChar(char ch){
int to = 0;
for (int from = 0; from < this.length; from++){
char nextch = this.buff[from];
if (nextch != ch){
this.buff[to] = nextch;
to++;
}
}
}
}
Here is what gcc generates when given: 给定gcc会生成以下内容:
void delete_char(char ch, char buf[], int len) {
int from, to;
for (from=0,to=0; from<len; ++from)
if (buf[from] != ch)
buf[to++] = buf[from];
}
_delete_char:
pushl %ebp
movl %esp, %ebp
subl $40, %esp
movl 8(%ebp), %eax
movb %al, -28(%ebp)
movl $0, -12(%ebp)
movl $0, -16(%ebp)
jmp L2
L3:
movl -12(%ebp), %eax
addl 12(%ebp), %eax
movb (%eax), %al
cmpb -28(%ebp), %al
je L4
movl -16(%ebp), %eax
movl %eax, %edx
addl 12(%ebp), %edx
movl -12(%ebp), %eax
addl 12(%ebp), %eax
movb (%eax), %al
movb %al, (%edx)
incl -16(%ebp)
L4:
incl -12(%ebp)
L2:
movl -12(%ebp), %eax
cmpl 16(%ebp), %eax
jl L3
leave
ret
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.