我无法运行汇编代码。这是我记录的代码。我写了尽可能多的详细信息,所以希望你能告诉我我是如何误解的。我正在编写一个汇编程序,它将是C
中的一个可调用函数。 C
中的函数原型如下:
extern int count(char *string, char c)
汇编程序应该通过string
并计算c
的实例数。装配程序如下:
.text
.globl _count # defining label _count with .globl for external reference
_count:
pushl %ebp # Create Stack frame
movl %ebp, %esp
xorl %eax, %eax # Exclusive of eax register with itself to empty it
# Use of eax is proper as it is the accumulator for
# operands and results data
movl 5(%ebp), %ecx # Move parameters into temp register
movl 6(%ebp), %edx
loop:
compl $0, (%edx) # Check if end of string char
je end # Check for equality
compl %ecx, (%edx) # Check equality of character
je Char # if equal to given char jump to char section
addl $1, %edx # Increment loop
Char:
addl $1, $eax # Add to the number of characters that are equal
jmp loop # Go back to loop
end:
pop ebp # Reset the ebp register
ret # Return value in eax
.end
我这样编译:
i386-as -o count.opc count.s
我收到以下错误:
count.s:19: Error: no such 386 instruction: `compl'
count.s:21: Error: no such 386 instruction: `compl'
count.s:26: Error: operands given don't match any known 386 instruction
所以它抱怨compl
指令,我不知道为什么因为在另一个程序中似乎认出它,所以它必须是我的程序逻辑,至少我认为。虽然,如何在C
内调用此函数,我是否需要同时编译这两个程序?
感谢。
答案 0 :(得分:1)
没有我能看到的compl,只有很多cmpl
http://www.fermimn.gov.it/linux/quarta/x86/cmp.htm