From c3c9d8910472310de22fbcae9abaa60f0c4ad9cd Mon Sep 17 00:00:00 2001 From: JackC Date: Thu, 11 Jun 2020 21:43:00 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=9F=A9=E9=98=B5=E4=B9=98=E6=B3=95.asm.?= =?UTF-8?q?=20=E7=AE=97=E6=98=AF=E7=BB=A7=E7=BA=A6=E7=91=9F=E5=A4=AB?= =?UTF-8?q?=E7=AE=97=E6=B3=95=E3=80=81=E5=90=8D=E5=AD=97=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E3=80=81=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=93=8D=E4=BD=9C=E7=AD=89?= =?UTF-8?q?=E6=B1=87=E7=BC=96=E4=BB=A3=E7=A0=81=E5=86=99=E8=BF=87=E6=AF=94?= =?UTF-8?q?=E8=BE=83=E5=A4=8D=E6=9D=82=E7=9A=84=E4=BB=A3=E7=A0=81=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E4=B9=9F=E6=98=AF=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E4=B8=96=E7=95=8C=E9=81=87=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E4=B8=AA=E7=AE=97=E6=B3=95(C=E8=AF=AD?= =?UTF-8?q?=E8=A8=80)=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\351\230\265\344\271\230\346\263\225.asm" | 246 ++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 "\347\237\251\351\230\265\344\271\230\346\263\225.asm" diff --git "a/\347\237\251\351\230\265\344\271\230\346\263\225.asm" "b/\347\237\251\351\230\265\344\271\230\346\263\225.asm" new file mode 100644 index 0000000..425ada7 --- /dev/null +++ "b/\347\237\251\351\230\265\344\271\230\346\263\225.asm" @@ -0,0 +1,246 @@ +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 \ No newline at end of file -- Gitee