The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: HW on October 27, 2006, 03:52:30 PM

Title: Adding Matrices using MASM32
Post by: HW on October 27, 2006, 03:52:30 PM
Hi there every one, can you please correct me on my program, i wanted to, Add array of the first row:

:This the Program

.data
        Dword 1  2
        Dword 4  5
.data?
  sum _3 DW 50 DUP(?)

.code
start

mov eax, [ table + 0]
mov esi, [ table + 1]
Add, esi
mov sum_3, eax
invoke stdout, Addr sum_3
end

Can you please get back to me in you have any idea if this program is correct or not, cause i tried to run it, but it shows the wrong addition.  Please help

Thanx
Title: Re: Adding Matrices using MASM32
Post by: gabor on October 27, 2006, 05:01:25 PM
Hello!

Well this looks like a homework to me...I may be wrong, but if it is a homework you should not excpect anybody to write it for you.
First of all I can see many syntax errors, have you read a tutorial? Like these: http://spiff.tripnet.se/~iczelion/tutorials.html

1. Model and processor type is missing. You want to use the Stdout function then its library must be included, like some other windows includes and libraries...

2. Here the coma is missing, also a symbol name for those dword data would be useful.
Quote from: HW on October 27, 2006, 03:52:30 PM
Dword 4 5

3. I suggest, but I may be wrong that some initialization is required. You cannot start with the main calculations.

4. Finally what would be the algo you want to code? Adding matrices, I suppose...
For first approach this must be a two level nested loop. 1 loop for stepping thru the rows, 1 loop for stepping thru the columns.

Greets, Gábor
Quote
Title: Re: Adding Matrices using MASM32
Post by: BogdanOntanu on October 28, 2006, 04:46:12 PM
Moved to the workshop because it was not related to MASM32 project.

HW... take care ... because we do NOT do other people's homeworks in here.

And please do NOT cross post the same question in multiple places/forums here!
Title: Re: Adding Matrices using MASM32
Post by: TNick on October 28, 2006, 05:15:27 PM
Hello, HW
Wlellcome aboard!

If I understand correctly, you would like to add all elements of an array and to output the sum. Well, this code will do that.
But, if you REALLY think about learning assambly, then you should REALLY read Iclezion's tutorials and play with the code. I am a "NooB" too, and there was my starting point.


    .486
    .model flat, stdcall
    option casemap :none

    include \masm32\include\windows.inc
    include \masm32\macros\macros.asm

;----------------------------------------
;include files that have MASM fromat protypes for function calls
;----------------------------------------

    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

;---------------------------------------
;Library files that have definition for function
;exports and tested relaible prebuilt code.
;---------------------------------------
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
.data

;array of 4 dwords
table        dword     1,3
             dword     2,2

;buffer to store the ascii output
;because the higher number that can be represented in 4 bytes is 4294967295,12 bytes will do the job
.data?
sum_3    BYTE     12 dub(?)

.code               
start:                         
;offset to our array
mov    edx,   OFFSET table
;ecx will be our counter
xor      ecx,    ecx
;eax will hold the sum
xor      eax,    eax
.while  ecx<4
      ;edx - offset to our array; ecx - counter; 4* - each dword have 4 bytes
      ;first pass: ecx=0 => dword ptr [edx+ecx*4]=1
      ;second pass: ecx=1 => dword ptr [edx+ecx*4]=3
      add      eax, dword ptr [edx+ecx*4]
      ;increase our counter by one
      inc ecx
.endw
;convert our number to decimal string
invoke       dwtoa,                      eax,addr sum_3
;or convert it to hexadecimal string
;invoke      dw2hex,                    eax,addr sum_3
;output the result to debuger's window
invoke       OutputDebugString,    addr sum_3

end start ;!!!!



Best regards,
Nick
Title: Re: Adding Matrices using MASM32
Post by: TheGreatJason on October 28, 2006, 06:38:26 PM
"A man ceases to be a beginner in chess assembly programming and becomes a master when he has learned that he is going to be a beginner all his life."
R. G. Collingwood (1889-1943), British philosopher.
:green :green :green

On the subject of matrices (as in the mathematical kind) has anyone got any MASM code to deal with that sort of thing?  Like Matrix Multiplication etc. etc.  Surprised there's nothing on Raymond's page about that sort of thing.  (Well I say that now, maybe there will be later...)
Title: Re: Adding Matrices using MASM32
Post by: Biterider on October 28, 2006, 07:25:16 PM
Hi
Look at ObjAsm32 project. You will find an object called Matrix that is exactly what you are looking for. Demo11A-C shows how to use it.

Regards,

Biterider
Title: Re: Adding Matrices using MASM32
Post by: gabor on October 29, 2006, 10:04:26 PM
Hello again!

Just wanted to post a question: weren't MMX instructions designed for supporting vector and matrix operations, were they?

Greets, Gábor
Title: Re: Adding Matrices using MASM32
Post by: u on October 31, 2006, 05:10:35 PM
SSE are, not mmx
Thus, SSE operations usually cope with doing arithmetic of 4 32-bit floats against 4 other floats at once. Thus, it takes 12 instructions to add two 4x4 matrices. The disadvantage is that after 3 or more operations on the same data, the precision gradually becomes worse (than FPU).