Author Topic: need help on matrix multplication in masm  (Read 17698 times)

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: need help on matrix multplication in masm
« Reply #15 on: February 16, 2013, 06:04:13 AM »
Matrix chain Multiplication:  multiplying more than 2 matrix in assembly

Ok ! Try to search «The calculator» ? It does what you want ?

waqar ahmad

  • Guest
Re: need help on matrix multplication in masm
« Reply #16 on: February 16, 2013, 06:21:18 AM »
I need assembly code of matrix multiplication.  not a calculator to multiply matrix

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: need help on matrix multplication in masm
« Reply #17 on: February 16, 2013, 06:27:29 AM »
I need assembly code of matrix multiplication.  not a calculator to multiply matrix
                  Yes the calculator was done in Assembly by magic waqar ahmad ;)

waqar ahmad

  • Guest
Re: need help on matrix multplication in masm
« Reply #18 on: February 16, 2013, 06:30:21 AM »
But where is the code of that calculator?

RuiLoureiro

  • Member
  • ****
  • Posts: 820
Re: need help on matrix multplication in masm
« Reply #19 on: February 16, 2013, 06:31:47 AM »
But where is the code of that calculator?
The author has the assembly code !

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10572
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: need help on matrix multplication in masm
« Reply #20 on: February 16, 2013, 07:38:02 PM »
The original question looks and sounds like homework. You have been asked to provide the code that you have developed to try and perform this task but cannot do so and have asked the most basic questions about writing Intel notation assembler code. It would appear that you want someone to do this for you which is not going to get done here. Members will help you to learn assembler coding but they will not do your work for you.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: need help on matrix multplication in masm
« Reply #21 on: February 16, 2013, 09:09:19 PM »
I have to do this in 16 bit

Meaning that you must code it as a 16-bit application, or that you must use only 16-bit registers? A 16-bit application must use 16-bit addressing, but this addressing can be done more easily using 32-bit registers.

Well Microsoft, here’s another nice mess you’ve gotten us into.

Gunther

  • Member
  • *****
  • Posts: 4178
  • Forgive your enemies, but never forget their names
Re: need help on matrix multplication in masm
« Reply #22 on: February 16, 2013, 10:10:48 PM »
Hi waqar ahmad,

The original question looks and sounds like homework. You have been asked to provide the code that you have developed to try and perform this task but cannot do so and have asked the most basic questions about writing Intel notation assembler code. It would appear that you want someone to do this for you which is not going to get done here. Members will help you to learn assembler coding but they will not do your work for you.

That is the central point. Try to write your 16 or 32 bit code (or whatever), post it here and we'll help you to get it working. That's the only way.

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

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: need help on matrix multplication in masm
« Reply #23 on: February 18, 2013, 07:04:28 PM »
I think the most reasonable starting point would be to learn how to access a 2-dimensional array with MASM. The information on the linked AoA page should make this relatively easy, start at 5.6.2 Multidimensional Arrays and continue through 5.6.2.4 Accessing Multidimensional Array Elements in Assembly Language. I think you should start with a 32-bit console app, because it will be easier to code and debug, and then after you get it working translate it to 16-bit. For ease of use I think you should encapsulate the code in a procedure, one to get an array element, and one to set an array element.

Note that the page shows 16-bit code, and the array elements are 16-bit words. Translating it to 32-bit code can be as simple as substituting 32-bit registers for the 16-bit registers and 32-bit dwords for the array elements, with the complication that to allow for the doubling in the size of the array elements the:
Code: [Select]
add ax, ax

Should be replaced with:
Code: [Select]
add eax, eax
add eax, eax

Or better:
Code: [Select]
shl eax, 2

Or you can reduce the number of instructions required by taking advantage of the additional addressing modes available in 32-bit code, but I’ll leave that explanation to someone else, after you demonstrate a willingness to do something beyond “research”.

Here is a 32-bit template with some test code (that depends on a working MASM32 installation) where for simplicity I reduced the array from the 8x4 in the AoA example to 4x4.
Code: [Select]
;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================
.data
    array dd 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
.code
;==============================================================================
;--------------------------------------------------------------------------
;     0   1   2   3
;    ---------------
; 0 | 00  01  02  03
; 1 | 04  05  06  07
; 2 | 08  09  10  11
; 3 | 12  13  14  15
;
; For a row major ordered array:
; Element_Address = Base_Address+(colindex*row_size+rowindex)*Element_Size
;--------------------------------------------------------------------------

;----------------------------------------------------------------------
; The convention for returning a 32-bit integer is to leave it in EAX.
;----------------------------------------------------------------------

Get proc colindex:DWORD, rowindex:DWORD
    ; your code goes here
    ret
Get endp

Set proc colindex:DWORD, rowindex:DWORD, value:DWORD
    ; your code goes here
    ret
Set endp

;==============================================================================
start:
;==============================================================================
    invoke Get, 0, 0
    printf("%d\n", eax)
    invoke Get, 0, 1
    printf("%d\n", eax)
    invoke Get, 0, 2
    printf("%d\n", eax)
    invoke Get, 0, 3
    printf("%d\n", eax)
    invoke Get, 1, 0
    printf("%d\n", eax)
    invoke Get, 1, 1
    printf("%d\n", eax)
    invoke Get, 1, 2
    printf("%d\n", eax)
    invoke Get, 1, 3
    printf("%d\n", eax)
    invoke Get, 2, 0
    printf("%d\n", eax)
    invoke Get, 2, 1
    printf("%d\n", eax)
    invoke Get, 2, 2
    printf("%d\n", eax)
    invoke Get, 2, 3
    printf("%d\n", eax)
    invoke Get, 3, 0
    printf("%d\n", eax)
    invoke Get, 3, 1
    printf("%d\n", eax)
    invoke Get, 3, 2
    printf("%d\n", eax)
    invoke Get, 3, 3
    printf("%d\n\n", eax)

    invoke Set, 0, 0, 0
    invoke Get, 0, 0
    printf("%d\n", eax)
    invoke Set, 0, 1, -1
    invoke Get, 0, 1
    printf("%d\n", eax)
    invoke Set, 0, 2, -2
    invoke Get, 0, 2
    printf("%d\n", eax)
    invoke Set, 0, 2, -3
    invoke Get, 0, 2
    printf("%d\n\n", eax)

    invoke Set, 3, 0, -12
    invoke Get, 3, 0
    printf("%d\n", eax)
    invoke Set, 3, 1, -13
    invoke Get, 3, 1
    printf("%d\n", eax)
    invoke Set, 3, 2, -14
    invoke Get, 3, 2
    printf("%d\n", eax)
    invoke Set, 3, 2, -15
    invoke Get, 3, 2
    printf("%d\n\n", eax)

    inkey
    exit
;==============================================================================
end start
Well Microsoft, here’s another nice mess you’ve gotten us into.

Stan

  • Regular Member
  • *
  • Posts: 20
Re: need help on matrix multplication in masm
« Reply #24 on: February 20, 2013, 08:41:48 AM »
@MichaelW

Good explanation.

Sometimes it's difficult for a student [AND MANY OTHERS] to grasp a concept when the structure is not blatantly apparent.
Showing the multi-dimensional array as a serial chunk -- excellent!