Skip to content

Instantly share code, notes, and snippets.

@moonblade
Created September 1, 2016 05:29
Show Gist options
  • Save moonblade/52f15a6ce488c5009773bc95ac51fcce to your computer and use it in GitHub Desktop.
Save moonblade/52f15a6ce488c5009773bc95ac51fcce to your computer and use it in GitHub Desktop.
;read size of first matrix into r0,r1
movx a,@dptr
mov r0,a
inc dptr
movx a,@dptr
mov r1,a
inc dptr
;move start of matrix to r2
mov r2,dpl
;read size of second matrix into r3,r4
mov a,#10h
mov dpl,a
movx a,@dptr
mov r3,a
inc dptr
movx a,@dptr
mov r4,a
inc dptr
;start of second matrix to r5
mov r5,dpl
;see if they are multiplicable
mov a,r1
subb a,r3
jz next
;can't multiply
mov a,#20h
mov dpl,a
mov a,#0ffh
movx @dptr,a
jmp ende
next:
;result dptr is in tl0
;set result size
mov tl0,#20h
mov dpl,tl0
mov a,r0
movx @dptr,a
inc dptr
mov a,r4
movx @dptr,a
inc dptr
mov tl0,dpl
;i going from 0 to r0-1 (i=r7)
mov r7,#0
outer:
;j going from 0 to r4-1 (j=r6)
mov r6,#0
inner:
;sum 0 (sum=th0)
mov th0,#0
;k going form 0 to r1-1 (k=th1)
mov th1,#0
ininner:
;sum+= a[i][k] + b[k][j]
;a[i][k]=a+i*n+k = r2 + r7*r1 + th1
mov a,r7
mov b,r1
mul ab
add a,r2
add a,th1
mov dpl,a
;read a[i][k] to tl1
movx a,@dptr
mov tl1,a
;b[k][j]=b+k*n+j = r5 + th1*r4 + r6
mov a,th1
mov b,r4
mul ab
add a,r5
add a,r6
mov dpl,a
;read a[k][j] to tl1
movx a,@dptr
mov b,tl1
mul ab
; add this product to sum (th0)
mov b,th0
add a,b
mov th0,a
; loop innner till k(th1) is r1
inc th1
mov a,th1
clr c
subb a,r1
jnz ininner
;c[i][j] = sum
;c[i][j] = c + i*n + j = tl0 + r7*r1 + r6
mov a,r7
mov b,r1
mul ab
add a,tl0
add a,r6
mov dpl,a
;print sum
mov a,th0
movx @dptr,a
inc th0
;loop till inner till j = r4
inc r6
mov a,r6
clr c
subb a,r4
jnz inner
;loop till outer till i = r0
inc r7
mov a,r7
clr c
subb a,r0
jnz outer
ende:
sjmp ende
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment