News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

need help on matrix multplication in masm

Started by waqar ahmad, February 15, 2013, 08:06:07 AM

Previous topic - Next topic

waqar ahmad

Hello everyone,
                        i need masm program of matrix chain multiplication or matrix multiplication. Please help me
            Thanks

qWord

you may shows us what you already have done?
MREAL macros - when you need floating point arithmetic while assembling!

waqar ahmad

I only done research. it is more confusing me. i have c language code which is very simple. but i don't know how to implement two dimensional array in masm.

jj2007

To get you started:
A two-dimensional array is an area of memory to which you have a pointer, e.g.

.data
MyArray DWORD 10, 11, 12, 13, 20, 21, 22, 23
R1C1  dd 0

You would load the start address into a register:
.code
  mov esi, offset MyArray

To get row 1, column 2, you would need to calculate the offset:
  cols=4
  mov eax, [esi+1*cols*DWORD+2*DWORD]
  mov R1C2, eax

waqar ahmad

Would you Please Explain This Line:

    mov eax, [esi+1*cols*DWORD+2*DWORD]

jj2007

mov eax, [esi+1*cols*DWORD+2*DWORD]

esi is the starting point to the memory block that contains your data
The example has 4 columns, and DWORD size, i.e. 4 bytes per item.
To load the dword in row1, column 2 (zero-based!), your offset is
  1*4*4+2*4
In this example, immediate values are used. You can also use e.g.
  mov ecx, 1  ; desired row
  mov edx, 2  ; desired column
  mov eax, 4  ; number of columns
  imul eax, ecx, DWORD  ; 4*ecx*4=16
  mov eax, [esi+eax+4*edx]
same as
  mov eax, [esi+4*4+4*2]

waqar ahmad

ok,  i have a link which has same functionality that you are applying would you please see this :
and explain it to me

http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH05/CH05-2.html

Gunther

Hi waqar ahmad,

first things first: welcome to the forum.

To  your link. It's a question what you would prefer: row major order like in C (first row, second row, ..., last row), or column major order like in FORTRAN, Pascal, BASIC (first column, second column, ..., last column). Furthermore, your pointed site is 16 bit code. But you should read the theoretical background and migrate the source to 32 bit code.

Gunther
You have to know the facts before you can distort them.

waqar ahmad

thanks,   I am doing doing matrix chain multiplication,   i am trying to convert c code into assembly. I am working on MASM in 16 bit..

RuiLoureiro

Quote from: waqar ahmad on February 16, 2013, 03:03:18 AM
...        I am working on MASM in 16 bit..

:biggrin:
Hi waqar ahmad,
                             16 bit is obsolete !
It is hard to code it !

waqar ahmad


waqar ahmad

I am not much Familiar with 32 bit but if matrix chain multiplication is available in 32 bit please tell me..

waqar ahmad

Anyone who can convert this line into assembly MASM:

work=c[j][k]+c[k+1][j+i]+p[j-1]*p[k]*p[j+i];

RuiLoureiro

Quote from: waqar ahmad on February 16, 2013, 05:14:03 AM
I am not much Familiar with 32 bit but if matrix chain multiplication is available in 32 bit please tell me..
Hi  waqar ahmad,
               1.  with 32 bit it is much easy.
               2.  could you explain to me what you want to say with
                    «matrix chain multiplication» ? What exatly .
               3. you can search this forum for «The calculator or go to page 18 now». It
                   can do some matrix multiplication etc.
Have a good work !  :biggrin:

waqar ahmad

Matrix chain Multiplication:  multiplying more than 2 matrix in assembly