4
回答
这些怎么翻译成汇编??
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   
//PTRD = 100, PTRA = 100
typedef struct
{
int width;
int height;
}Size;


typedef struct {
int x;
int y;
}Point;


bool clipLine(Size img_size, Point &pt1, Point &pt2)
{
int x1, y1, x2, y2;
int c1, c2;
int right = img_size.width - 1, bottom = img_size.height - 1;


if (img_size.width <= 0 || img_size.height <= 0)
return false;
x1 = pt1.x; y1 = pt1.y;
x2 = pt2.x; y2 = pt2.y;


c1 = x1 < 0 + (x1 > right) * 2 + (y1 < 0) * 4 + (y1 > bottom) * 8;
c2 = x2 < 0 + (x2 > right) * 2 + (y2 < 0) * 4 + (y2 > bottom) * 8;


if ((c1 & c2) == 0 && (c1 | c2) != 0) {
int a;
if (c1 & 12) {
a = c1 < 8 ? 0 : bottom;
x1 += (int)(((int64) ( a - y1 )) * (x2 - x1) / (y2 - y1));
y1 = a;
c1 = (x1 < 0) + (x1 > right) * 2;
}
...
}
}


int main(void)
{
Size img = {10,10};
Point t1 = {1,1}, t2 = {18, 8};
clipLine(img, t1, t2);
return 0;

}

// 翻译成汇编该怎么做?下面的翻译的对不对?该怎么解释??谢谢各位大神

MOV (0x400), (0x06) ;参数地址
MOV (0x401), (0x07)
MOV (0x402), (0x08)
MOV (0x403), (0x09)
MOV (0x404), (0x0a)
MOV (0x405), (0x0b)
ADD PTR1, PTR0, (1) ;设置被调用函数FUNC的基地址
ADD PTR2, PTR0, (0) ;0存放了当前函数的基地址
CALL FUNC          ;绝对地址
...
FUNC: MOV (2), PTR2 ;存储调用者的基地址
ADDI PTR3, PTR0, #1
SUBI (12), (0x400), PTR3
SUBI (13), (0x401), PTR3
MOV (6), (0x402)
MOV (7), (0x403)
MOV (8), (0x404)
MOV (9), (0x405)
BLT (6), PTR0, #X11
MOV R1, PTR0
X1RIGHT: BGT (6), (12), #X12
MOV R2, PTR0
Y10: BLT (7), PTR0, #Y11
MOV R3, PTR0
Y1BOTTOM: BLT (7), (13), #Y81
MOV R4, PTR0
JUMP #SUM
X11: ADDI R1, PTR0, #1
JUMP #X1RIGHT
X12: ADDI R2, PTR0, #2
JUMP #Y10
Y11: ADDI R3, PTR0, #4
JUMP #Y1BOTTOM
Y81: ADDI R4, PTR0, #8
SUM: ADD (10), R1, R2
ADD (10), R2, (10)
ADD (10), R3, (10)
BLT (8), PTR0, #X11
MOV R1, PTR0
X2RIGHT: BGT (8), (12), #X21
MOV R2, PTR0
Y20: BLT (9), PTR0, #Y21
MOV R3, PTR0
Y2BOTTOM: BLT (9), (13), #YB81
MOV R4, PTR0
JUMP #SUM
X21: ADDI R1, PTR0, #1
JUMP #X2RIGHT
X21: ADDI R2, PTR0, #2
JUMP #Y20
Y21: ADDI R3, PTR0, #4
JUMP #Y2BOTTOM
YB81: ADDI R4, PTR0, #8
SUM: ADD (11), R1, R2
ADD (11), R2, (11)
ADD (11), R3, (11)
AND R4, (10), (11)
BNE R4, PTR0, #NON_CLIP
OR R4, (10), (11)
BEQ R4, PTR0, #NON_CLIP
ADDI R4, PTR0, #12
BEQ R4, PTR0, #C212
ADDI R5, PTR0, #8


C212: ...
NON_CLIP1: MOV PTR1, (2)  ;恢复调用者的基地址
RET 

举报
共有4个答案 最后回答: 5年前
objdump
--- 共有 9 条评论 ---
超级大坏蛋回复 @中山野鬼 : 好吧 你知道怎么做么??呵呵 5年前 回复
中山野鬼回复 @超级大坏蛋 : 你不会另起一个回复?为什么非要在评论中追加呢??哈。 5年前 回复
超级大坏蛋@中山野鬼 呵呵 给你传不了 你知道怎么把.cpp文件在linux下反汇编么??objdump只是针对可执行文件的 5年前 回复
中山野鬼回复 @超级大坏蛋 : 我已然花眼了。哈。 5年前 回复
超级大坏蛋@中山野鬼 #include "precomp.hpp" namespace cv { template<typename T, typename AT> void acc_( const T* src, AT* dst, const uchar* mask, int len, int cn ) { int i = 0; if( !mask ) { len *= cn; for( ; i <= len - 4; i += 4 ) { AT t0, t1; t0 = src[i] + dst[i]; t1 = src[i+1] + dst[i+1]; dst[i] = t0; dst[i+1] = t1; t0 = src[i+2] + dst[i+2]; t1 = src[i+3] + dst[i+3]; dst[i+2] = t0; dst[i+3] = t1; } for( ; i < len; i++ ) dst[i] += src[i]; } else if( cn == 1 ) { for( ; i < len; i++ ) { if( mask[i] ) dst[i] += src[i]; } } else if( cn == 3 ) { for( ; i < len; i++, src += 3, dst += 3 ) { if( mask[i] ) { AT t0 = src0 + dst0; AT t1 = src1 + dst1; AT t2 = src2 + dst2; dst[0] = t0; dst[1] = t1; dst[2] = t2; } } } else { for( ; i < len; i++, src += cn, dst += cn ) if( mask[i] ) { for( int k = 0; k < cn; k++ ) dst[k] += src[k]; } } } template<typename T, typename AT> void accSqr_( const T* src, AT* dst, const uchar* mask, int len, int cn ) { int i = 0; if( !mask ) { len *= cn; for( ; i <= len - 4; i += 4 ) { AT t0, t1; t0 = (AT)src[i]*src[i] + dst[i]; t1 = (AT)src[i+1]*src[i+1] + dst[i+1]; dst[i] = t0; dst[i+1] = t1; t0 = (AT)src[i+2]*src[i+2] + dst[i+2]; t1 = (AT)src[i+3]*src[i+3] + dst[i+3]; dst[i+2] = t0; dst[i+3] = t1; } for( ; i < len; i++ ) dst[i] += (AT)src[i]*src[i]; } else if( cn == 1 ) { for( ; i < len; i++ ) { if( mask[i] ) dst[i] += (AT)src[i]*src[i]; } } else if( cn == 3 ) { for( ; i < len; i++, src += 3, dst += 3 ) { if( mask[i] ) { AT t0 = (AT)src[0]*src[0] + dst[0]; AT t1 = (AT)src[1]*src[1] + dst[1]; AT t2 = (AT)src[2]*src[2] + dst[2]; dst[0] = t0; dst[1] = t1; dst[2] = t2; } } } else { for( ; i < len; i++, src += cn, dst += cn ) if( mask[i] ) { for( int k = 0; k < cn; k++ ) dst[k] += (AT)src[k]*src[k]; } } } template<typename T, typename AT> void accProd_( const T* src1, const T* src2, AT* dst, const uchar* mask, int len, int cn ) { int i = 0; if( !mask ) { len *= cn; for( ; i <= len - 4; i += 4 ) { AT t0, t1; t0 = (AT)src1[i]*src2[i] + dst[i]; t1 = (AT)src1[i+1]*src2[i+1] + dst[i+1]; dst[i] = t0; dst[i+1] = t1; t0 = (AT)src1[i+2]*src2[i+2] + dst[i+2]; t1 = (AT)src1[i+3]*src2[i+3] + dst[i+3]; dst[i+2] = t0; dst[i+3] = t1; } for( ; i < len; i++ ) dst[i] += (AT)src1[i]*src2[i]; } else if( cn == 1 ) { for( ; i < len; i++ ) { if( mask[i] ) dst[i] += (AT)src1[i]*src2[i]; } } else if( cn == 3 ) { for( ; i < len; i++, src1 += 3, src2 += 3, dst += 3 ) { if( mask[i] ) { AT t0 = (AT)src1[0]*src2[0] + dst[0]; AT t1 = (AT)src1[1]*src2[1] + dst[1]; AT t2 = (AT)src1[2]*src2[2] + dst[2]; dst[0] = t0; dst[1] = t1; dst[2] = t2; } } } else { for( ; i < len; i++, src1 += cn, src2 += cn, dst += cn ) if( mask[i] ) { for( int k = 0; k < cn; k++ ) dst[k] += (AT)src1[k]*src2[k]; } } } template<typename T, typename AT> void accW_( const T* src, AT* dst, const uchar* mask, int len, int cn, double alpha ) { AT a = (AT)alpha, b = 1 - a; int i = 0; if( !mask ) { len *= cn; for( ; i <= len - 4; i += 4 ) { AT t0, t1; t0 = src[i]*a + dst[i]*b; t1 = src[i+1]*a + dst[i+1]*b; dst[i] = t0; dst[i+1] = t1; t0 = src[i+2]*a + dst[i+2]*b; t1 = src[i+3]*a + dst[i+3]*b; dst[i+2] = t0; dst[i+3] = t1; } for( ; i < len; i++ ) dst[i] = src[i]*a + dst[i]*b; } else if( cn == 1 ) { for( ; i < len; i++ ) { if( mask[i] ) dst[i] = src[i]*a + dst[i]*b; } } else if( cn == 3 ) { for( ; i < len; i++, src += 3, dst += 3 ) { if( mask[i] ) { AT t0 = src[0]*a + dst[0]*b; AT t1 = src[1]*a + dst[1]*b; AT t2 = src[2]*a + dst[2]*b; dst[0] = t0; dst[1] = t1; dst[2] = t2; } } } else { for( ; i < len; i++, src += cn, dst += cn ) if( mask[i] ) { for( int k = 0; k < cn; k++ ) dst[k] += src[k]*a + dst[k]*b; } } } #define DEF_ACC_FUNCS(suffix, type, acctype) \ static void acc_##suffix(const type* src, acctype* dst, \ const uchar* mask, int len, int cn) \ { acc_(src, dst, mask, len, cn); } \ \ static void accSqr_##suffix(const type* src, acctype* dst, \ const uchar* mask, int len, int cn) \ { accSqr_(src, dst, mask, len, cn); } \ \ static void accProd_##suffix(const type* src1, const type* src2, \ acctype* dst, const uchar* mask, int len, int cn) \ { accProd_(src1, src2, dst, mask, len, cn); } \ \ static void accW_##suffix(const type* src, acctype* dst, \ const uchar* mask, int len, int cn, double alpha) \ { accW_(src, dst, mask, len, cn, alpha); } DEF_ACC_FUNCS(8u32f, uchar, float) DEF_ACC_FUNCS(8u64f, uchar, double) DEF_ACC_FUNCS(16u32f, ushort, float) DEF_ACC_FUNCS(16u64f, ushort, double) DEF_ACC_FUNCS(32f, float, float) DEF_ACC_FUNCS(32f64f, float, double) DEF_ACC_FUNCS(64f, double, double) typedef void (*AccFunc)(const uchar*, uchar*, const uchar*, int, int); typedef void (*AccProdFunc)(const uchar*, const uchar*, uchar*, const uchar*, int, int); typedef void (*AccWFunc)(const uchar*, uchar*, const uchar*, int, int, double); static AccFunc accTab[] = { (AccFunc)acc_8u32f, (AccFunc)acc_8u64f, (AccFunc)acc_16u32f, (AccFunc)acc_16u64f, (AccFunc)acc_32f, (AccFunc)acc_32f64f, (AccFunc)acc_64f }; static AccFunc accSqrTab[] = { (AccFunc)accSqr_8u32f, (AccFunc)accSqr_8u64f, (AccFunc)accSqr_16u32f, (AccFunc)accSqr_16u64f, (AccFunc)accSqr_32f, (AccFunc)accSqr_32f64f, (AccFunc)accSqr_64f }; static AccProdFunc accProdTab[] = { (AccProdFunc)accProd_8u32f, (AccProdFunc)accProd_8u64f, (AccProdFunc)accProd_16u32f, (AccProdFunc)accProd_16u64f, (AccProdFunc)accProd_32f, (AccProdFunc)accProd_32f64f, (AccProdFunc)accProd_64f }; static AccWFunc accWTab[] = { (AccWFunc)accW_8u32f, (AccWFunc)accW_8u64f, (AccWFunc)accW_16u32f, (AccWFunc)accW_16u64f, (AccWFunc)accW_32f, (AccWFunc)accW_32f64f, (AccWFunc)accW_64f }; inline int getAccTabIdx(int sdepth, int ddepth) { return sdepth == CV_8U && ddepth == CV_32F ? 0 : sdepth == CV_8U && ddepth == CV_64F ? 1 : sdepth == CV_16U && ddepth == CV_32F ? 2 : sdepth == CV_16U && ddepth == CV_64F ? 3 : sdepth == CV_32F && ddepth == CV_32F ? 4 : sdepth == CV_32F && ddepth == CV_64F ? 5 : sdepth == CV_64F && ddepth == CV_64F ? 6 : -1; } } void cv::accumulate( InputArray _src, InputOutputArray _dst, InputArray _mask ) { Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat(); int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels(); CV_Assert( dst.size == src.size && dst.channels() == cn ); CV_Assert( mask.empty() || (mask.size == src.size && mask.type() == CV_8U) ); int fidx = getAccTabIdx(sdepth, ddepth); AccFunc func = fidx >= 0 ? accTab[fidx] : 0; CV_Assert( func != 0 ); const Mat* arrays[] = {&src, &dst, &mask, 0}; uchar* ptrs[3]; NAryMatIterator it(arrays, ptrs); int len = (int)it.size; for( size_t i = 0; i < it.nplanes; i++, ++it ) func(ptrs[0], ptrs[1], ptrs[2], len, cn); } void cv::accumulateSquare( InputArray _src, InputOutputArray _dst, InputArray _mask ) { Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat(); int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels(); CV_Assert( dst.size == src.size && dst.channels() == cn ); CV_Assert( mask.empty() || (mask.size == src.size && mask.type() == CV_8U) ); int fidx = getAccTabIdx(sdepth, ddepth); AccFunc func = fidx >= 0 ? accSqrTab[fidx] : 0; CV_Assert( func != 0 ); const Mat* arrays[] = {&src, &dst, &mask, 0}; uchar* ptrs[3]; NAryMatIterator it(arrays, ptrs); int len = (int)it.size; for( size_t i = 0; i < it.nplanes; i++, ++it ) func(ptrs[0], ptrs[1], ptrs[2], len, cn); } void cv::accumulateProduct( InputArray _src1, InputArray _src2, InputOutputArray _dst, InputArray _mask ) { Mat src1 = _src1.getMat(), src2 = _src2.getMat(), dst = _dst.getMat(), mask = _mask.getMat(); int sdepth = src1.depth(), ddepth = dst.depth(), cn = src1.channels(); CV_Assert( src2.size && src1.size && src2.type() == src1.type() ); CV_Assert( dst.size == src1.size && dst.channels() == cn ); CV_Assert( mask.empty() || (mask.size == src1.size && mask.type() == CV_8U) ); int fidx = getAccTabIdx(sdepth, ddepth); AccProdFunc func = fidx >= 0 ? accProdTab[fidx] : 0; CV_Assert( func != 0 ); const Mat* arrays[] = {&src1, &src2, &dst, &mask, 0}; uchar* ptrs[4]; NAryMatIterator it(arrays, ptrs); int len = (int)it.size; for( size_t i = 0; i < it.nplanes; i++, ++it ) func(ptrs[0], ptrs[1], ptrs[2], ptrs[3], len, cn); } void cv::accumulateWeighted( InputArray _src, InputOutputArray _dst, double alpha, InputArray _mask ) { Mat src = _src.getMat(), dst = _dst.getMat(), mask = _mask.getMat(); int sdepth = src.depth(), ddepth = dst.depth(), cn = src.channels(); CV_Assert( dst.size == src.size && dst.channels() == cn ); CV_Assert( mask.empty() || (mask.size == src.size && mask.type() == CV_8U) ); int fidx = getAccTabIdx(sdepth, ddepth); AccWFunc func = fidx >= 0 ? accWTab[fidx] : 0; CV_Assert( func != 0 ); const Mat* arrays[] = {&src, &dst, &mask, 0}; uchar* ptrs[3]; NAryMatIterator it(arrays, ptrs); int len = (int)it.size; for( size_t i = 0; i < it.nplanes; i++, ++it ) func(ptrs[0], ptrs[1], ptrs[2], len, cn, alpha); } CV_IMPL void cvAcc( const void* arr, void* sumarr, const void* maskarr ) { cv::Mat src = cv::cvarrToMat(arr), dst = cv::cvarrToMat(sumarr), mask; if( maskarr ) mask = cv::cvarrToMat(maskarr); cv::accumulate( src, dst, mask ); } CV_IMPL void cvSquareAcc( const void* arr, void* sumarr, const void* maskarr ) { cv::Mat src = cv::cvarrToMat(arr), dst = cv::cvarrToMat(sumarr), mask; if( maskarr ) mask = cv::cvarrToMat(maskarr); cv::accumulateSquare( src, dst, mask ); } CV_IMPL void cvMultiplyAcc( const void* arr1, const void* arr2, void* sumarr, const void* maskarr ) { cv::Mat src1 = cv::cvarrToMat(arr1), src2 = cv::cvarrToMat(arr2); cv::Mat dst = cv::cvarrToMat(sumarr), mask; if( maskarr ) mask = cv::cvarrToMat(maskarr); cv::accumulateProduct( src1, src2, dst, mask ); } CV_IMPL void cvRunningAvg( const void* arr, void* sumarr, double alpha, const void* maskarr ) { cv::Mat src = cv::cvarrToMat(arr), dst = cv::cvarrToMat(sumarr), mask; if( maskarr ) mask = cv::cvarrToMat(maskarr); cv::accumulateWeighted( src, dst, alpha, mask ); } /* End of file. */ 5年前 回复
弄成汇编做什么啊,移植到裸奔机都不至于用汇编,如果想生成汇编代码来作优化分析的话,编译器都支持输出汇编代码的,配置下就可以。
--- 共有 5 条评论 ---
超级大坏蛋@超级大坏蛋 你懂不懂opencv呀 哥们 5年前 回复
超级大坏蛋@cut 谢谢 5年前 回复
cut回复 @超级大坏蛋 : gcc编译器 gcc -s icc编译器 icl /O2 /s hello.c vc编译器 /FAs 手写汇编就一个蛋疼,不过你搞编译器的,最好还是手写汇编体验下,一般编译器不是必须还是有汇编器的么,你先在你的汇编器上写汇编看看。 5年前 回复
超级大坏蛋不行 你知道 centos下g++的包名叫什么??我的系统里没有这个命令。我用 yum install gcc-g++ 不行 5年前 回复
超级大坏蛋呵呵 我们在做编译器 所以的用汇编跑一跑 5年前 回复
顶部