我正在编写一个汇编程序,它将采用两个3X6矩阵,添加它们,然后将结果放入一个新矩阵。我遇到了一些问题。
问题是矩阵1只输出2-16而矩阵2输出20-34。我似乎无法弄清楚如何使用矩阵。
%include "io.mac"
.STACK 100H
.DATA
NO_ROWS EQU 3
NO_COLUMNS EQU 5
SIZE_OF_ROW EQU 5
SIZE_OF_ENTRY EQU 2
matrix1
dw 1,2,3,4,5,6
dw 7,8,9,10,11,12
dw 13,14,15,16,17,18
matrix2
dw 19,20,21,22,23,24
dw 25,26,27,28,29,30
dw 31,32,33,34,35,36
matrix3 TIMES 40 DW 0
.CODE
.STARTUP
mov CX, NO_ROWS ; set outer loop count
L1: ; begin the outer loop
push CX ; save outer loop count
mov BX, CX ;move outer loop count into EAX
sub bx, 1
mov CX, 5 ; set inner loop count
L2:
; use formula arrayName + (elements_in_a_row*row_number + element) *size_of_entry
mov si, 0
mov di, 0
mov dx, 0
mov si, matrix1
mov di, matrix2
mov ax, SIZE_OF_ROW
mul bx ;multiply ax by which row you're on.
add ax, cx ;then add column count, for which column you're on.
shl ax, 1 ;then multiply it by the size of each entry.
add si, ax ; so that the index points to the element.
add di, ax
mov ax, [si]
add ax, [di]
mov [matrix3], ax
PutInt [matrix3]
nwln
add word [matrix3], 2
loop L2 ; repeat inner loop
pop CX ;restore outer loop
loop L1 ;repeat outer loop
done:
.EXIT