.model small
.stack 100h
.data
a dw 1, 2, 3, 4, 5, 6, 7, 8, 9
b dw 9, 8, 7, 6, 5, 4, 3, 2, 1
c dw 0, 0, 0, 0, 0, 0, 0, 0, 0
scalar dw 2
.code
mov ax, @data
mov ds, ax
; Matrix multiplication
mov cx, 3 ; outer loop counter (rows of a)
mov di, 0 ; index for a
mov si, 0 ; index for b
multiply_loop:
push cx ; save outer loop counter
mov bx, 0 ; index for c
mov dx, 0 ; inner loop counter
inner_loop:
mov ax, a[di]
mov bx, b[si]
mul bx
add c[bx], ax
add di, 2 ; move to next element in a
add si, 2 ; move to next element in b
inc dx ; increment inner loop counter
cmp dx, 3 ; check if inner loop counter reached 3
jl inner_loop ; if not, continue inner loop
pop cx ; restore outer loop counter
add di, 2 ; move to next row in a
mov si, 0 ; reset index for b
inc bx ; increment index for c
cmp bx, 3 ; check if outer loop counter reached 3
jl multiply_loop ; if not, continue outer loop
; Print the result of matrix multiplication
mov ah, 2 ; print character function
mov dl, 13 ; carriage return
int 21h
mov dl, 10 ; line feed
int 21h
mov cx, 9 ; total elements in c
mov di, 0 ; index for c
print_loop:
mov ax, c[di]
add ax, 48 ; convert to ASCII
mov dl, al ; move lower byte to dl
mov ah, 2 ; print character function
int 21h
inc di ; move to next element in c
loop print_loop ; continue printing until all elements are printed
; Multiply the result by the scalar
mov cx, 9 ; total elements in c
mov di, 0 ; index for c
mov ax, scalar
multiply_scalar_loop:
mul c[di]
mov c[di], ax
inc di ; move to next element in c
loop multiply_scalar_loop ; continue multiplying until all elements are multiplied
; Print the result after scalar multiplication
mov ah, 2 ; print character function
mov dl, 13 ; carriage return
int 21h
mov dl, 10 ; line feed
int 21h
mov cx, 9 ; total elements in c
mov di, 0 ; index for c
print_scalar_loop:
mov ax, c[di]
add ax, 48 ; convert to ASCII
mov dl, al ; move lower byte to dl
mov ah, 2 ; print character function
int 21h
inc di ; move to next element in c
loop print_scalar_loop ; continue printing until all elements are printed
mov ax, 4C00h ; exit program
int 21h
end
Can someone help me with this code, it's printing some symbols and zeros when I run it. Where is the error?
I tried to multiply 2 matrices and to multiply result matrix with scalar and it's not printing good.

All of your matrices are 2 dimensional (3 x 3); they're even square matrices. It will be much clearer if you wrote your definitions that way too:
Multiplying
If BX is supposed to contain an offset in the c array, why then do you destroy that value in loading from the b array (
mov bx, b[si]) ?If DX is supposed to contain your inner loop counter, why then do you allow it getting destroyed by the word-sized multiplication
mul bxthat leaves a product in the register combo DX:AX ?You need to make up your mind here! The outer loop counter is in CX; why then look at BX ? And the index for the c array would have to increment in steps of 2 since it is a word-sized array.
In all, your matrix multiplication doesn't do what it needs to do. You are on a learning path here, so please don't expect me to write it all for you, but in the past I have answered a similar question that you can study and that should help you find it mostly on your own.
Printing
In the print loop, you seem to expect that the elements in the c array will all be in the single-digit range. This will not be the case! You need a conversion code that can convert the value in AX into a string of characters. I have prepared such a code in Displaying numbers with DOS.
Multiplying again
In this loop you need to reload the scalar on every iteration, not just the first time. And to actually "move to next element in c", you need to add 2 instead of 1.
Printing again
Exactly the same as above.
Good luck
Once you get this much better and it still doesn't work, then don't hesitate and post your improved code stating whatever problems remain.