c - 汇编:没有这样的386指令

标签 c assembly

我在运行汇编代码时遇到问题。这是我记录的代码。我写了尽可能多的细节,所以希望你能告诉我我是如何误解事情的。我正在编写一个汇编程序,它将成为 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/

相关文章:

C OpenGL glfw3 三角形不显示

c - 在 C 中,给定一个可变的参数列表,如何使用它们构建函数调用?

c - gcc 循环构造对汇编代码的更改

c - 'switch' 比 'if' 快吗?

c - AVR RTOS 的内联 C 汇编器宏

c - 哈希算法的实现将字符串转换为数字

c - 如何在 C 中的任何 linux 发行版上解析/proc/cpuinfo

c - 如何优化我发送的套接字消息的大小,而不丢失任何数据?

C 编程、unicode 和 linux 终端

c - 我正在尝试将此功能转换为程序集,但我不明白它在做什么