The problem is that I have a condition where an element should be added to the sum. If the sum of the indices of the element ( j+i>4 ), then add the element to the sum; otherwise, ignore it.
I tried to run it:
#include <iostream>
using namespace std;
const int n = 4;
int main() {
int A[n][n] = {
{10000, 2000, 4000, 10000},
{6000, 1, 1, 1},
{11000, 1, 1, 1},
{160000, 1, 1, 1}
};
int sum = 0;
__asm
{
mov ecx, 0
outer_loop:
mov ebx, 0
inner_loop :
mov eax, A
mov edx, ecx
imul edx, n
add edx, ebx
cmp ecx, 0
jle next_column
cmp ebx, 0
jle next_column
mov eax, [A + 4 * edx]
add sum, eax
next_column :
inc ebx
cmp ebx, n
jl inner_loop
inc ecx
cmp ecx, n
jl outer_loop
}
cout << "Sum of elements where i + j > 4: " << sum << endl;
return 0;
}
Output:
Sum of elements where i + j > 4: 9
What is wrong in my code?
New contributor
Batsamut Nikita is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.