C语言嵌汇编的问题

来源:百度知道 编辑:UC知道 时间:2024/05/14 19:01:13
#include"stdio.h"
int c ( int m , int n )
{
asm mov ax,0
asm mov cx,m
asm s: add ax,n
asm loop s

return ( _AX );
}
int main ( )
{
int m,n;
scanf ( "%d%d",&m,&n ) ;
printf ( "%d",c ( m,n ) );

return 0;
}

程序的功能是计算两个正整数的积,不知道要怎么写,大家帮我来修改下
编绎器是tcc,masm

用其他编绎器也行,只要给出工具和操作方法
不能使用+-*/等运算符
算法:n*m相当于m个n相加
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

D:\temp\c>tcc 7.c
Turbo C Version 2.0 Copyright (c) 1987, 1988 Borland International
7.c:
Error 7.c 10: Undefined symbol '__asm' in function main
Warning 7.c 10: Code has no effect in function main
Error 7.c 10: Statement missing ; in function main
Warning 7.c 18: 'b' is assigned a value which is never used in function main
Warning 7.c 18: 'a' is as

忘说了,我用的是vc:

#include <stdio.h>

int main()
{
int a = 1234151;
int b = 12312341;
unsigned long long c;
__asm
{
mov eax, dword ptr [a]
mul dword ptr [b]
mov dword ptr [c], eax
mov dword ptr [c+4], edx
}

printf("%llu\n", c);
}

/*
你所使用的C编译器可能不支持内联汇编或者被关闭了。
下面的代码在VC++6 即可通过,结果也符合你的逻辑。
*/

#include"stdio.h"
int c ( int m , int n )
{
_asm sub eax,eax
_asm mov ecx,m
_asm s: add eax,n
_asm loop s
return;
}
int main ()
{
int m,n;
scanf ( "%d%d",&m,&n ) ;
printf ( "%d",c( m,n ) );
return 0;
}