954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sum of elements in matrix

Write a program which for a square matrix to calculate the sum of the elements. Assume that the amount can be placed in 16-bit register

Example:


1 1 1
2 2 2
3 3 3

Elements are: 1,1, 2, which are with red color. I had calculate sum of this elements.

Please help me!!!

kikiritce
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

DX will contain required sum:

mov     dx,0
        mov     esi,matr
        mov     ecx,0
        mov     cx,[dimmatr]
        mov     eax,1
mRow:
        push    ecx

        mov     cx,[dimmatr]
        mov     ebx,0
mCol:
        cmp     ebx,eax
        jl      msk
        add     dx,word [esi]
msk:
        inc     ebx
        add     esi,2
        loop    mCol
        inc     eax

        pop     ecx
        loop    mRow

dimmatr dw 3;matrix dimension
matr    dw 1,1,1,2,2,2,3,3,3;matrix
skaa
Light Poster
36 posts since Jan 2011
Reputation Points: 13
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: