0

This is using easy68K. Hi, I am multiplying two matrices together. I declare constants in a linear fashion at the bottom of the code.But basically I have two matrices, 2 x 2. I am saving in matrix D which has a defined storage. And into the second loop when I go up an address, I get an error:

Address Error: Instruction at 1028 accessing address 1063 Execution halted

Here is an image:

http://i1107.photobucket.com/albums/h385/Nazariy1995/Problem.png

Here is my code:

r   EQU     2   ;number of rows
c   EQU     2   ;number of columns
    ORG    $1000
START:  MOVEA.L     #A,A0
        MOVEA.L     #B,A1
        MOVEA.L     #D,A2

        MOVE.W      #r,D3   ;used for rows
        CLR.W       D0  ;offset for A
        CLR.W       D1  ;offset for B
        CLR.W       D2  ;offset for D
        CLR.W       D5  ;calculating the sum
        CLR.W       D6  ;calculaing the multiplication
        CLR.W       D7  ;used for number of repeats
L2      MOVE.W      #c,D4   ;used for columns mainly for first matrix 
L1      CLR.W       D5
        MOVE.W      (A0,D0.W),D5
        MULU        (A1,D1.W),D5
        ADD.W       D5,D6
        ADD.W       #1,D0
        ADD.W       #c,D1   ;we are moving down a column and thus are adding column to the offset in B
        SUB.W       #1,D4
        BNE         L1
        MOVE.W      D6,(A2,D2.W)
        ADD.W       #1,D2   ;increment counter for C
        ADD.W       #1,D7   ;increment repeat
        CMP.W       #c,D7   ;number of repeats  should be equal to column number
        BNE         RE
        CLR.W       D7      ;clear repeats because we are moving on to a new row
        CLR.W       D1      ;set offset for B to 0
        SUB.W       #1,D3   ;find out through how many rows we went through
        BNE         L2
        STOP        #$2700

RE      SUB.W      #c,D0    ;got at the beginning of a row in A
        MOVE.W      D7,D1
        CLR.W       D6
        BSR        L2

* Put program code here

    SIMHALT             ; halt simulator

* Put variables and constants here
A   DC.W    1,2,0,1
B   DC.W    1,0,2,1
D   DS.W    4

    END    START        ; last line of source

Please help! I know a little about assembly, and it's just difficult. Thanks in advance!

Nazariy
  • 717
  • 6
  • 23
  • You have the tool, use it to single step your code and see how it ends up with the incorrect address. Check that each instruction is doing what you want. – Jester Mar 02 '15 at 18:59
  • I did I went through it step by step, with step over, I am just not understanding how is it that and address can be wrong. Maybe my displacement is wrong, in terms of word, or by or long word ? – Nazariy Mar 02 '15 at 19:33
  • 1
    A word is 2 bytes, and addresses use bytes. Thus, you need to increment your pointers by 2. – Jester Mar 02 '15 at 19:40
  • 1
    (A0, D0.w*2) is, I believe, the syntax to increase the scale of an index. As it is, you are incrementing by 1 and then trying to access a Word from an odd numbered location. Remember that words must be 2-byte aligned and longs, 4-byte. (You might also want to look at the addq instruction). – Mike Mar 03 '15 at 06:58
  • Thank you everyone! Mike and Jester you guys are correct. That it what fixed my program. Funny, my teacher couldn't even find the problem. So Thank you so much! – Nazariy Mar 03 '15 at 21:23

0 Answers0