我在运行汇编代码时遇到问题。这是我记录的代码。我写了尽可能多的细节,所以希望你能告诉我我是如何误解事情的。我正在编写一个汇编程序,它将成为 C
中的一个可调用函数。 C
中的函数原型(prototype)如下:
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 内部调用这个函数,我需要同时编译这两个程序吗?
谢谢。
最佳答案
我没有看到任何 compl,只有很多 cmpl
http://www.fermimn.gov.it/linux/quarta/x86/cmp.htm
关于c - 汇编:没有这样的386指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28908953/