5 Star 50 Fork 0

Gitee Community / 码力传递:晒代码赢奖品

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
矩阵乘法.asm 3.20 KB
一键复制 编辑 原始数据 按行查看 历史
JackC 提交于 2020-06-11 21:43 . add 矩阵乘法.asm.
assume cs:code, ds:data, ss:stack
data segment
column db ?
row db ?
matrix1 db 100 dup('$')
matrix2 db 100 dup('$')
matrix3 dw 100 dup('$')
str1 db 'Please input column: $'
str2 db 'Please input row: $'
str3 db 'Please input matrix1: $'
str4 db 'Please input matrix2: $'
str5 db 'The matrix after multiplying is: $'
temp dw ?
multiplier db ?
multiplicand db ?
data ends
stack segment para stack
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
lea dx, str1 ; 输入矩阵的行和列
call disp_str
call in_1_dec
mov column, al
call cr
lea dx, str2
call disp_str
call in_1_dec
mov row, al
call cr
lea dx, str3
call disp_str
call cr
mov bl, row
mov bh, 0
lea si, matrix1
s0: ; 输入第一个矩阵
cmp bx, 0
je s1
mov cl, column
mov ch, 0
s0_0:
call in_1_dec
mov byte ptr [si], al
inc si
call space
loop s0_0
call cr
dec bx
jmp s0
s1:
lea dx, str4
call disp_str
call cr
mov bl, column
mov bh, 0
lea si, matrix2
s2: ; 输入第二个矩阵
cmp bx, 0
je s3
mov cl, row
mov ch, 0
s2_0:
call in_1_dec
mov byte ptr [si], al
inc si
call space
loop s2_0
call cr
dec bx
jmp s2
s3:
lea si, matrix1
lea di, matrix2
lea bp, matrix3
mov cl, 0
s4: ; 矩阵乘法
cmp cl, row
jz s5
mov dx, 0
s4_2:
cmp dl, row
jz s4_0
mov bx, 0
mov temp, 0
s4_3:
cmp bl, column
jz s4_1
mov al, byte ptr[si + bx] ; 取出第一矩阵的数
mov multiplier, al
mov al, row
mul bl
push bx
mov bl, al
add bl, dl
mov bh, 0
mov al, byte ptr [di + bx] ; 取出第2矩阵的数
mov bl, multiplier
mul bl
mov bx, temp
mov ah, 0
add bx, ax
mov temp, bx
pop bx
inc bl
jmp s4_3
s4_1:
mov ax, temp
mov word ptr ds:[bp], ax
add bp, 2
inc dl
jmp s4_2
s4_0:
mov al, column
mov ah, 0
add si, ax
inc cl
jmp s4
s5:
lea dx, str5
call disp_str
call cr
mov cl, 0
lea si, matrix3
s6: ; 输出相乘后的矩阵
cmp cl, row
jz s7
mov bx, 0
s6_1:
cmp bl, row
jz s6_0
mov ax, [si]
call disp_4_hex ; 这里要用4位16进制输出,原因是:当row = 9, col = 9, 以及数据全为9时,就有81 * 9 = 729D = 2D9H,故要用4位16进制数
call space
inc bl
add si, 2
jmp s6_1
s6_0:
call cr
inc cl
jmp s6
s7:
mov ax, 4c00h
int 21h
space:
push ax
push dx
mov ah, 02h
mov dl, 20h
int 21h
pop dx
pop ax
ret
cr:
push ax
push dx
mov ah, 02h
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
pop dx
pop ax
ret
disp_1_hex:
push ax
push dx
pushf
mov ah, 02h
mov dl, al
cmp dl, 9
jna disp_1_hex_1
add dl, 07h
disp_1_hex_1:
add dl, 30h
int 21h
popf
pop dx
pop ax
ret
disp_2_hex:
push bx
push ax
pushf
mov bl, 10h
mov ah, 0
div bl
call disp_1_hex
mov al, ah
call disp_1_hex
popf
pop ax
pop bx
ret
disp_4_hex:
push bx
push ax
pushf
mov bl, al
mov al, ah
call disp_2_hex
mov al, bl
call disp_2_hex
popf
pop ax
pop bx
ret
disp_str:
push ax
pushf
mov ah, 09h
int 21h
popf
pop ax
ret
in_1_dec:
pushf
mov ah, 01h
int 21h
sub al, 30h
popf
ret
code ends
end start
1
https://gitee.com/gitee-community/gitee-7th-event-3.git
git@gitee.com:gitee-community/gitee-7th-event-3.git
gitee-community
gitee-7th-event-3
码力传递:晒代码赢奖品
master

搜索帮助