EASy68K
http://www.easy68k.com/EASy68Kforum/

matrix calculation
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1151
Page 1 of 1

Author:  mrmode [ Wed Dec 12, 2012 7:24 am ]
Post subject:  matrix calculation

i. Ask for a square input matrix A (2 x 2)
ii. Ask for a square input matrix B (2 x 2)
iii. Perform the matrix multiplication of A x B.
iv. Display the results to the screen in the following manners:
[matrix A]
x
[matrix B]
=
[matrix C]


can anyone give some idea how to do this.

Author:  lee [ Wed Dec 12, 2012 9:14 am ]
Post subject:  Re: matrix calculation

The way I'd tackle it is to break each step into smaller steps until I can start writing some code.

For example this step ..
Quote:
i. Ask for a square input matrix A (2 x 2)
.. could be broken into the following ..
Code:
a. Display the user prompt text
b. Get the matrix values
c. Save them in memory
.. the first part of this I could code as ..
Code:
      LEA         prompt1(pc),a1    * get the prompt string address
      MOVEQ       #14,d0            * display a string without [CR][LF]
      TRAP        #15


prompt1
      dc.b  "<prompt text goes here>",$00
Keep doing this and eventually you have a program.

Lee.

Author:  mrmode [ Mon Dec 17, 2012 1:36 am ]
Post subject:  Re: matrix calculation

can you plx tell how to take hex key from keyboard

Author:  mrmode [ Mon Dec 17, 2012 2:23 am ]
Post subject:  Re: matrix calculation

with this i can select data from keyboard.... but i do not know how to go to control the data and where they are stored.... when each number is displayed i want it to be stored in a different register after that i have to multiply and add them ... anyone plx tell me how to do this.

ORG $1000
SIZE equ 4 ; data size (4 bytes for long word)

START: ; first instruction of program

* read 10 numbers from keyboard and store in array
lea array1,A0 ; pointer to array

for D2 = #0 to #0*SIZE by #SIZE do.s ; loop 10 times
lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D2) ; store number to array at index D2
endf

lea result,A1 ; pointer to string
move.b #13,D0 ; display result
trap #15

Author:  mrmode [ Mon Dec 17, 2012 3:40 am ]
Post subject:  Re: matrix calculation

When i add i cannot show the actual result... this gives a wrong answer.....so plx tell me how to fix this


ORG $1000
SIZE equ 4 ; data size (4 bytes for long word)

START: ; first instruction of program

* read 10 numbers from keyboard and store in array
lea array1,A0 ; pointer to array


lea prompt,A1 ; pointer to string
move.w #50,d1
move.w #290,d2
move.b #13,d0 place message on screen
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D0) ; store number to array at index D2




lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D1) ; store number to array at index D2



lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D2) ; store number to array at index D2


lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D3) ; store number to array at index D2

lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D4) ; store number to array at index D2
lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D5) ; store number to array at index D2

lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D6) ; store number to array at index D2

lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D7) ; store number to array at index D2


move.l (A0,D0),D0
move.l (A0,D1),D1
move.l (A0,D2),D2
move.l (A0,D3),D3
move.l (A0,D4),D4
move.l (A0,D5),D5
move.l (A0,D6),D6
move.l (A0,D7),D7





MULU D0,D4
MULU D1,D6

ADD.W D4,D6
* display numbers from array

move.l D6,D1 ; get number from array at index D0
move.b #3,D0 ; display number in D1.L
trap #15

MOVE.B #9,D0
TRAP #15 ; halt simulator


* Variables and Strings
array1 ds.l 8 ; 10 long word array
prompt dc.b 'Enter a number: ',0 ; null terminated string
result dc.b 'Your numbers are: ',0 ; null terminated string
crlf dc.b $d,$a,0 ; carriage return, line feed, null

END START ; last line of source

Author:  lee [ Mon Dec 17, 2012 6:14 am ]
Post subject:  Re: matrix calculation

Code:
      MOVE.l      d1,(a0,d0)        ; store number to array at index d2
Firstly your comment doesn't agree with your code, secondly you haven't set any value for the index. Also you don't advance the index after a value is saved. E.g.
Code:
      MOVEQ       #0,d2             ; initialise the index

... code to get a value goes here ...

      MOVE.l      d1,(a0,d2.w)      ; store number to array a0 at index d2
      ADDQ.w      #size,d2          ; increment the array index to the next element
Rather than repeating whole chunks of code over and over you should consider a short loop with a counter to get all the numbers into the array.
Code:
array1
      ds.l  8                       ; 10 long word array
Some more of your code where the actual code and comments don't match.

Lee.

Author:  mrmode [ Mon Dec 17, 2012 7:39 am ]
Post subject:  Re: matrix calculation

the thing is im trying to do a matrix... i want to know where my values are stored. then only i can multiply them...

lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D7)

lea prompt,A1 ; pointer to string
move.b #13,D0 ; display prompt
trap #15

move.b #4,D0 ; read number from keyboard into D1.L
trap #15

move.l D1,(A0,D5)

this displaces the no. and i know my no is at (A0,D7) and (A0,D7)...

so now i can move it to D1 and multiply it with another number.. for that i used
MULU D5,D7


than when i add the result to another number im getting a very different answer...
move.l #42,d2
add D2,d7



so plx explain how to solve this problem.

Author:  mrmode [ Mon Dec 17, 2012 8:20 am ]
Post subject:  Re: matrix calculation

plx give an idea how to do this

Author:  lee [ Mon Dec 17, 2012 2:04 pm ]
Post subject:  Re: matrix calculation

To use a register as an index to an array you have to put a value in the register. E.g.

Code:
      MOVEQ       #0,d2             ; sets d2 = 0, first element

      . . .

      ADDQ.w      #size.d2          ; sets d2 = d2 + size, the next element
      MOVE.l      d1,(a0,d2.w)      ; store the number in the array at index d2
To access the nth element of the array the index needs to be set to size*(n-1)

Code:
      MOVEQ       #size*4,d2        ; sets d2 = the fifth element
      MOVE.l      (a0,d2.w),d1      ; get the number in the array at index d2
All these accesses use the same address and data register to access the array.

Lee.

Author:  mrmode [ Mon Dec 17, 2012 4:01 pm ]
Post subject:  Re: matrix calculation

i have done that can you plx tell me how to display my matrix result one after the other..

lea MSG15,A1
move.b #13,D0 ; display prompt
trap #15

move.l D6,D1
move.l D7,D2
move.l A4,D3
move.l A6,D4

mulu D1,D3
mulu D2,D4

Add.w D3,D4
move.l D4,D1
move.b #3,D0
trap #15

MOVE.B #9,D0
TRAP #15 ; halt simulator

lea MSG16,A1
move.b #13,D0 ; display prompt
trap #15

move.l D6,D1
move.l D7,D2
move.l A5,D3
move.l A7,D4

mulu D1,D3
mulu D2,D4

Add.w D3,D4
move.l D4,D1
move.b #3,D0
trap #15
this only shows msg 15 but not msg 16

Author:  clive [ Mon Dec 17, 2012 4:09 pm ]
Post subject:  Re: matrix calculation

Quote:
this only shows msg 15 but not msg 16

Don't halt simulation after msg 15 then.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/