I need some major help with my motorola micrcontroller programming assignment

csyberblue

Senior member
Aug 1, 2002
808
0
0
I have this assignment due tomorrow, for my microcontroller programming class.

I know I'm screwed on it, but I thought I'd give it a shot and ask you guys for help.

The task is to do addition, subtraction and multiplication of a 4x4 matrix. Each of those tasks needs to be a subroutine. The values of the matrices are going to be given to us when we show the teacher our running code.

Here's the code for add for addition without subroutines:

N equ 2 ;The matrix is a NxN
j equ 8 ;j is how many values are in the 2 matrices

org $1000 ;program execution begins at location 2000
sum rmb 2 ;reserve memory byte 2
i rmb 1 ;reserve memory byte 1
m rmb 1 ;reserve memory byte 1
mat_a db 0,1,2,3,4,5,6,7 ;the 2 matrices together

;Addition portion
org $2100 ;the program is starting here at location 2100
clr i ;clearing the index i
clr sum ;clearing the sum
clr sum+1 ;clearing sum+1
ldaa N ;load into accumulator A, N
ldab N ;load into accumulator B, N
mul ;multiply the two locations together
staa N ;store the new value into N (N is now N^2)

loop_a ldaa i ;starting the loop, load into acc. a, i
cmpa #N ;compare what is in acc. A with N
beq done ;branch if they are equal to done (the program ends)

ldx #mat_a ;load into register x, the pointer for the 1st matrix
ldy #mat_a+N ;load into register y, the pointer for the 2nd matrix
sty $1200 ;store the pointer in location y into memory location 1200
ldab $1200 ;load the value stored in memory location 1200
abx ;add the values of b and x
stx $1400 ;store the new added value into memory location 1400
inc i ;then increment i
dbne b,loop_a ;decrement branch back to addition loop

done swi ;completes the program
end

This part is not being calculated right for some reason, and it nots giving a right answer.

I've tried talking to the teacher for help, but there's other students in his office and he hasn't been available.

any help from you guys would really be appreciated. thanks in advance.