Im new with an assembler.Couldn’t find the solution in the ethernet so asking here. This code outputs wrong numbers and i can’t get why.
#include <iostream>
long DotProduct(short int* vec1, short int* vec2, int l)
{
long result;
_asm
{
mov esi, [vec1];
mov edi, [vec2];
mov ecx, [l];
xor eax, eax;
loop_start:
movzx edx, word ptr[esi];
imul edx, word ptr[edi];
add eax, edx;
add esi, 2;
add edi, 2;
sub ecx, 1;
jnz loop_start;
}
return result;
}
int main() {
short int vec1[] = { 1, 2, 3 };
short int vec2[] = { 5, 6, 7 };
int l = 3;
long result = DotProduct(vec1, vec2, l);
std::cout << "Dot product: " << result << std::endl;
}
New contributor
Sheesh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.