源文件是这样的:
#include "mul_mod64.h"
add64(add_sub64 *v)
{
u32 y1;
y1 = abs(y);
if( (v->xs == 1) && (y>=0) )
{
v->zl = v->xl + y;
if(v->zl < v->xl)
{
v->zh = v->xh + 1;
}
else
{
v->zh = v->xh;
}
v->zs = 1;
}
else if( (v->xs == 1) && (y<0) )
{
if(v->xl >= y1)
{
v->zh = v->xh;
v->zl = v->xl - y1;
v->zs = 0;
}
else
{
if(v->xh >= 1)
{
v->zl = v->xl - y1;
v->zh = v->xh - 1;
v->zs = 1;
}
else
{
v->zl = y1 - v->xl ;
v->zh = 1;
v->zs = 0;
}
}
}
else if( (v->xs == 0) && (y>=0) )
{
if(v->xl >= y)
{
v->zh = v->xh;
v->zl = v->xl - y;
v->zs = 0;
}
else
{
if(v->xh >= 1)
{
v->zl = v->xl - y;
v->zh = v->xh - 1;
v->zs = 0;
}
else
{
v->zl = y - v->xl ;
v->zh = 0;
v->zs = 1;
}
}
}
else if( (v->xs == 0) && (y<0) )
{
v->zl = v->xl + y1;
if(v->zl < v->xl)
{
v->zh = v->xh + 1;
}
else
{
v->zh = v->xh;
}
v->zs = 0;
}
}
sub64(add_sub64 *v)
{
u32 y1;
y1 = abs(y);
if( (v->xs == 1) && (y>=0) )
{
v->zl = v->xl + y;
if(v->zl < v->xl)
{
v->zh = v->xh + 1;
}
else
{
v->zh = v->xh;
}
v->zs = 1;
}
else if( (v->xs == 1) && (y<0) )
{
if(v->xl >= y1)
{
v->zh = v->xh;
v->zl = v->xl - y1;
v->zs = 0;
}
else
{
if(v->xh >= 1)
{
v->zl = v->xl - y1;
v->zh = v->xh - 1;
v->zs = 1;
}
else
{
v->zl = y1 - v->xl ;
v->zh = 1;
v->zs = 0;
}
}
}
else if( (v->xs == 0) && (y>=0) )
{
if(v->xl >= y)
{
v->zh = v->xh;
v->zl = v->xl - y;
v->zs = 0;
}
else
{
if(v->xh >= 1)
{
v->zl = v->xl - y;
v->zh = v->xh - 1;
v->zs = 0;
}
else
{
v->zl = y - v->xl ;
v->zh = 0;
v->zs = 1;
}
}
}
else if( (v->xs == 0) && (y<0) )
{
v->zl = v->xl + y1;
if(v->zl < v->xl)
{
v->zh = v->xh + 1;
}
else
{
v->zh = v->xh;
}
v->zs = 0;
}
}
mul64(mul_mod64 *v)
{
u32 u0,v0,w0;
u32 u1,v1,w1,w2,t;
u0 = v->xl & 0xFFFF; u1 = v->xl >> 16;
v0 = v->y & 0xFFFF; v1 = 0;
w0 = u0*v0;
t = u1*v0 + (w0 >> 16);
w1 = t & 0xFFFF;
w2 = t >> 16;
v->zh = w2 + (w1 >> 16) + v->xh*v->y;
v->zl = u*v;
v->zs = v->xs;
}
mod64(mul_mod64 *v)
{
u32 u0,v0,w0;
u32 u1,v1,w1,u2;
v->zh = v->xh/v->y;
u0 = v->xh%y;
v0 = (v->xl>>10) & 0x3fffff;
w0 = (u0<<22) + v0;
u1 = w0/v->y;
v1 = w0%v->y;
w1 = v1<<10 + v->xl & 0x3ff ;
u2 = w1/v->y;
v->zl = u1<<22 + u2;
v->zs = v->xs;
}
头文件:
#ifndef __MUL_MOD64_H
#define __MUL_MOD64_H
#include "stm32f10x.h"
typedef struct
{
u32 xh;
u32 xl;
u32 xs;
u32 y;
u32 zh;
u32 zl;
u32 zs;
}mul_mod64;
typedef struct
{
u32 xh;
u32 xl;
u32 xs;
u32 yh;
u32 yl;
u32 ys;
u32 y;
u32 zh;
u32 zl;
u32 zs;
}add_sub64;
#endif
在IAR环境下完全正常,移植到keil下编译就出现如下提示:
Build target 'SFQD88'
compiling mul_mod64.c...
..HARDWAREmul_mod64.c(8): warning: #223-D: function "abs" declared implicitly
y1 = abs(y);
..HARDWAREmul_mod64.c(8): error: #20: identifier "y" is undefined
y1 = abs(y);
..HARDWAREmul_mod64.c(93): warning: #223-D: function "abs" declared implicitly
y1 = abs(y);
..HARDWAREmul_mod64.c(93): error: #20: identifier "y" is undefined
y1 = abs(y);
..HARDWAREmul_mod64.c(192): error: #20: identifier "u" is undefined
v->zl = u*v;
..HARDWAREmul_mod64.c(192): error: #32: expression must have arithmetic type
v->zl = u*v;
..HARDWAREmul_mod64.c(178): warning: #550-D: variable "v1" was set but never used
u32 u1,v1,w1,w2,t;
..HARDWAREmul_mod64.c(207): error: #20: identifier "y" is undefined
u0 = v->xh%y;
..HARDWAREmul_mod64.c: 3 warnings, 5 errors
"..OBJTemplate.axf" - 5 Error(s), 3 Warning(s).
Target not created.
Build Time Elapsed: 00:00:02
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>