Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何在32位汇编中编译?_C_Windows_Gcc_Assembly_X86 - Fatal编程技术网

C 如何在32位汇编中编译?

C 如何在32位汇编中编译?,c,windows,gcc,assembly,x86,C,Windows,Gcc,Assembly,X86,嘿,我在我的c代码中使用了一个32汇编函数。我用nasm和gcc编译它 nasm -f coff array1.asm gcc -o array1 array1.o array1c.c 我总是会出错: A array1c.c:9:1: warning: ‘cdecl’ attribute ignored [-Wattributes] int PRE_CDECL asm_main( void ) POST_CDECL; ^~~ array1c.c:10:1: warning: ‘cdecl’

嘿,我在我的c代码中使用了一个32汇编函数。我用nasm和gcc编译它

nasm -f coff array1.asm
gcc -o array1 array1.o array1c.c
我总是会出错:

A
array1c.c:9:1: warning: ‘cdecl’ attribute ignored [-Wattributes]
 int PRE_CDECL asm_main( void ) POST_CDECL;
 ^~~
array1c.c:10:1: warning: ‘cdecl’ attribute ignored [-Wattributes]
 void PRE_CDECL dump_line( void ) POST_CDECL;
 ^~~~
/usr/bin/ld: i386-Architektur der Eingabedatei »array1.o« ist inkompatibel zur Ausgabe i386:x86-64
collect2: error: ld returned 1 exit status
这是我的密码:

/*
 * Driver file for array1.asm file
 */

#include <stdio.h>

#include "cdecl.h"

int PRE_CDECL asm_main( void ) POST_CDECL;
void PRE_CDECL dump_line( void ) POST_CDECL;

int main()
{
  int ret_status;
  ret_status = asm_main();
  return ret_status;
}

/*
 * function dump_line
 * dumps all chars left in current line from input buffer
 */
void dump_line()
{
  int ch;

  while( (ch = getchar()) != EOF && ch != '\n')
    /* null body*/ ;
}

/*
*array1.asm文件的驱动程序文件
*/
#包括
#包括“cdecl.h”
int PRE_CDECL asm_main(无效)POST_CDECL;
作废前CDECL转储行(作废)后CDECL;
int main()
{
国际关系状况;
ret_status=asm_main();
返回ret_状态;
}
/*
*函数转储线
*从输入缓冲区转储当前行中剩余的所有字符
*/
无效转储_行()
{
int-ch;
而((ch=getchar())!=EOF&&ch!='\n')
/*空体*/;
}

您应该使用
gcc-m32
将代码编译为32位,如下所示:

nasm -f coff array1.asm
gcc -m32 -o array1 array1.o array1c.c

使用
gcc-m32
。注意
cdecl
是默认的调用约定,因此不需要设置
cdecl
。为什么在汇编程序输出中使用
coff
二进制格式。ELF二进制格式有什么问题吗?