It is currently Fri May 29, 2020 4:26 am

 All times are UTC

 Page 1 of 1 [ 11 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: matrix calculationPosted: Wed Dec 12, 2012 7:24 am

Joined: Thu Nov 15, 2012 7:29 pm
Posts: 13
Location: malaysia
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.

Top

 Post subject: Re: matrix calculationPosted: Wed Dec 12, 2012 9:14 am

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
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.

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 1:36 am

Joined: Thu Nov 15, 2012 7:29 pm
Posts: 13
Location: malaysia
can you plx tell how to take hex key from keyboard

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 2:23 am

Joined: Thu Nov 15, 2012 7:29 pm
Posts: 13
Location: malaysia
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

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 3:40 am

Joined: Thu Nov 15, 2012 7:29 pm
Posts: 13
Location: malaysia
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

* 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

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 6:14 am

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
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.

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 7:39 am

Joined: Thu Nov 15, 2012 7:29 pm
Posts: 13
Location: malaysia
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

so plx explain how to solve this problem.

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 8:20 am

Joined: Thu Nov 15, 2012 7:29 pm
Posts: 13
Location: malaysia
plx give an idea how to do this

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 2:04 pm

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
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.

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 4:01 pm

Joined: Thu Nov 15, 2012 7:29 pm
Posts: 13
Location: malaysia
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

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

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

Top

 Post subject: Re: matrix calculationPosted: Mon Dec 17, 2012 4:09 pm

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
Quote:
this only shows msg 15 but not msg 16

Don't halt simulation after msg 15 then.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 11 posts ]

 All times are UTC

Who is online

Users browsing this forum: No registered users and 9 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects