-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_addition.asm
71 lines (48 loc) · 1.26 KB
/
matrix_addition.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
; Author - Jatin Rohilla
; Course - MCA 102
; Objective - Implement MATRIX ADDITION
; data segment
DATA SEGMENT
MatrixA DB 01h,02h,03h
DB 04h,05h,06h
DB 07h,08h,09h
MatrixB DB 01h,02h,03h
DB 04h,05h,06h
DB 07h,08h,09h
SUM DB 9 DUP (?)
DATA ENDS
; code segmentt
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
; clear AX and carry
XOR AX,AX
MOV BP,0
MOV DI,BP
MOV CX,3
OUTER:
; save index of outer loop
PUSH CX
; inner loop needs to run 3 (column) times
MOV CX,3
; starting from index 0
MOV DI,0
INNER:
; move element of matrix A to AL
MOV AL,MatrixA[BP][DI]
; add AX to element of MATRIX B
ADD AL,MatrixB[BP][DI]
; save the addition result to SUM
MOV SUM[BP][DI],AL
; next index
INC DI
LOOP INNER
; Retrive index of outer loop
POP CX
; We need to go to next row, so we add 3 to skip the entire current row
ADD BP,3
LOOP OUTER
CODE ENDS
END START