Add 3×3 matrix in assembly

Lately my friend need to get homework done, the homework is interesting enough to tackle. Actually this is just a simple arithmetic problem, to Add 2 3×3 matrix but in 8085 assembly. So lets get it done🙂

This is the result :

if you want some highlighting, you can view at this link.

 

;
;ada dua matrix 3×3
;matrix satu pada alamat 0000h-0008h
;matrix dua pada alamat 0010h-0018h
; struktur data [1-3][4-6][7-9]

jmp start

;data

;code
start: nop
;array 1
;|1 5 3|
;|2 8 9|
;|2 3 5|
; 1-3
lxi h,0000h ; 1
mvi m,0001h
lxi h,0001h ; 2
mvi m,0005h
lxi h,0002h ; 3
mvi m,0003h
; 4-6
lxi h,0003h ; 4
mvi m,0002h
lxi h,0004h ; 5
mvi m,0008h
lxi h,0005h ; 6
mvi m,0009h
; 7-9
lxi h,0006h ; 7
mvi m,0002h
lxi h,0007h ; 8
mvi m,0003h
lxi h,0008h ; 9
mvi m,0005h
;array 2
;|5 7 3|
;|1 3 4|
;|2 3 6|
; 1-3
lxi h,0010h ; 1
mvi m,0005h
lxi h,0011h ; 2
mvi m,0007h
lxi h,0012h ; 3
mvi m,0003h
; 4-6
lxi h,0013h ; 4
mvi m,0001h
lxi h,0014h ; 5
mvi m,0003h
lxi h,0015h ; 6
mvi m,0004h
; 7-9
lxi h,0016h ; 7
mvi m,0002h
lxi h,0017h ; 8
mvi m,0003h
lxi h,0018h ; 9
mvi m,0006h

;persiapan sebelum looping
MVI C,00h ;set nilai awal
MVI E,10h ;set nilai awal

soop: nop
;MOV H,B ;Isi M dengan alamat matrix 1
LDAX B ;Isi A dengan data matrix 1
;MOV H,D ;Isi M dengan alamat matrix 2
MVI H,00H
MOV L,E
ADD M ;Add Matrix 1 dan Matrix 2
;STAX H ;Isi M dengan Hasil penjumlahan
MOV M,A
INR C
INR E
; kalau ada carry
; A < 0009h
; A alamat array 1 yang ditunjuk loop saat ini
MOV A, C
CPI 0009h
JC soop

hlt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s