Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data segment
- n1 dw ?
- n2 dw ?
- n3 dw ?
- array1 dw 100 dup(0)
- array2 dw 100 dup(0)
- array3 dw 100 dup(0)
- sumRow dw ?
- sumCol dw ?
- finalSum dw ?
- minSize dw ?
- newline db 13,10,'$'
- answer db 7 dup(?),'$'
- buffer db 06,00,5 dup(?)
- msgEnterN db 'Input size of matrix: $'
- msgEl db 13,10,'Input elements: ',13,10,'$'
- msgSumRow db 'Sum of 1st row: $'
- msgSumCol db 'Sum of last col: $'
- msgFinalSum db 'Final sum: $'
- msgLowestSize db 'Lowest size: $'
- msgRes db 'Result: $'
- data ends
- code segment
- assume cs:code,ds:data
- ; ????????? ?????????????? ????????? ????? ? ?????? ????????
- ; B??? - AX - ?????
- ; B???? - ?????? ?? ?????? DS:BX
- bin2str proc
- push dx
- push cx
- push bx
- push si
- push ax
- mov cx,6
- fill_buff: mov byte ptr[bx+1],'' ; ????????? ?????? ?????????
- inc bx
- loop fill_buff
- mov si,10 ; |SI|:=10
- or ax,ax ; ? |AX| - ????????????? ?????
- jns clr_div ; ???? +, ??????? ?? clr_div
- neg ax ; ?????, ?????? ????
- clr_div: sub dx,dx ; ???????? ??????? ???????? ????????
- div si ; |DX:AX| / 10
- add dx,'0' ; ????????????? ? ?????????? ???
- dec bx ; |BX|--
- mov [bx+1],dl ; ????????? ???????. ????? ? ??????
- or ax,ax ; ? ???????? ax - 0?
- jnz clr_div ; ???? ?? 0, ?????????
- pop ax ;
- or ax,ax ; ???????? ????? ???????????? ?
- jns no_more ; ???? ???, ??????? ? no_more
- dec bx ; |BX|--
- mov byte ptr[bx+1],'-' ; ????????? ? ?????? ???? '-'
- no_more: pop si
- pop bx
- mov byte ptr[bx],6 ; ????????? ??????? ????????
- pop cx
- pop dx
- ret
- bin2str endp
- ; ????????? ?????????????? ?????? ???????? ? ???????? ?????
- ; B??? - DS:BX - ????? ??????
- ; B???? - AX - ????? ?? ??????
- str2bin proc
- push bx
- push cx
- sub AX,AX
- sub ch,ch
- mov cl,byte ptr[bx] ; ??????? ???????? - ? CX
- blanks: cmp byte ptr[bx+1],'' ; ???? ???????? ????????
- jne chk_neg
- inc bx
- loop blanks
- jmp good ; ?? ?????????? ?????. ????????? - 0
- ; ????????? ??????? ??????????? ? ?????? ????? "-"
- chk_neg: cmp byte ptr[bx+1],'-'
- jne chk_pos
- inc bx ; ?????????? ?????????
- dec cx ; ????????? ???????
- call conv_ab ; ??????? ????????? ??????????????
- jc thru
- cmp AX,32768 ; ????? < -32768
- ja no_good ; ??, ??????
- neg AX ; ???????? ???? ?????
- js good ; OK, ???????
- ; ????????? ??????? ??????????? ? ??????, ???? ???? ?? ?????
- chk_pos: cmp byte ptr[bx+1],'+'; sign '+'?
- jne go_conv ; ???, ???? ?? ??????????????
- inc bx ; ???????? ????????? ? ??????
- dec cx ; ????????? ??????? ????????
- go_conv: call conv_ab ; ????????????? ?????? ? ?????
- jc thru ; ? ?????? ?????? - ?? ?????
- cmp AX,32767 ; ????? ?? ??????? ???????
- ja no_good ; ??????? ??????, ??????
- good: clc ; ???????? ???? CY
- jnc thru
- no_good: stc ; Set carry flag
- thru: pop cx ; ???????????? ???????? ?????????
- pop bx
- jmp skipit
- ;
- ; ????????? ?????????? ?????????????? ?????
- conv_ab proc
- push bp
- push bx
- push si
- mov bp,bx ; ????????? ????????? ?? ?????? ? BX
- xor bx,bx ; ???????? BX
- range: cmp byte ptr ds:[bp+1],'0' ; ?????? - ????? ?
- jb non_dig ; ??? ?? ?????
- cmp byte ptr ds:[bp+1],'9' ; ?????? > '9'
- jbe digit ; ?????? - ?????
- non_dig: stc ; ?????????? ???? ??????
- jc end_conv ; ? ????? ?? ?????????
- digit: mov si,10
- push dx ; ????????? DX
- mul si ; |Ax| * |SI| -> |DX:AX|
- pop dx ; ???????????? DX
- mov bl,ds:[bp+1] ; ????? ????????? ?????? ?? ??????
- and bx,0fh ; ????????????? ?????? ? ????????
- add AX,bx ; ???????? ????? ? ??????? ??????????
- jc end_conv ; ???? ????????? ??????? ?????, ?? ?????
- inc bp ; ????? ???? ????? ? ??????
- loop range ; ???????? ???? ?? ?????????? ????????
- clc ; ???????? ???? ???????? (??? ??????)
- end_conv: pop si ; ???????????? ???????? ? ?????
- pop bx
- pop bp
- ret
- conv_ab endp
- skipit: ret
- str2bin endp
- ;????? ?? ????? ??????????? str - ??????
- write macro str
- push ax
- push dx
- lea dx,str
- mov ah,09h
- int 21h
- pop dx
- pop ax
- endm
- ;???? ????? ? ??????????
- ;?????: ????? ? ax
- InputDigit macro
- push bx
- push dx
- write newline
- lea dx,buffer
- mov ah,0ah
- int 21h
- mov bx,dx
- inc bx
- call str2bin; ? bx - ????? ??????, ax - ?????
- pop dx
- pop bx
- endm
- ;????? ????? ? ?? ?? ?????
- OutputDigit macro
- push bx
- push dx
- lea bx,answer
- call bin2str ; ? ax ?????, ? bx - ????? ??????
- lea dx,[answer+1]
- mov ah,09h
- int 21h
- pop dx
- pop bx
- endm
- ; ?????? ??????? ???????
- ; matrix - ????? ??????? n- ???????????
- InputMatrix macro matrix,n
- Local i,j; i - ?? ???????? j -?? ???????
- push bx
- push ax
- lea bx,matrix
- mov cx,n
- i:
- push cx
- mov cx,n
- mov si,0
- j:
- InputDigit
- mov word ptr[bx][si],ax
- add si,2
- loop j
- add bx,n
- add bx,n
- pop cx
- loop i
- pop ax
- pop bx
- endm
- OutputMatrix macro matrix,n
- local i,j
- lea bx,matrix
- mov cx,n
- i:
- push cx
- mov cx,n
- mov si,0
- write newline
- j:
- xor ax,ax
- mov ax,word ptr[bx][si]
- OutputDigit
- add si,2
- loop j
- add bx,n
- add bx,n
- pop cx
- loop i
- ENDM
- ; ?????? ?????????? ?????????????? ???????? ? ?????????
- ; matrix - ????? ??????? n- ?? ???????????
- FuncMatrix macro matrix,n
- local view1
- mov sumCol,0
- mov sumRow,0
- push bx
- lea bx,matrix
- mov cx,n
- mov si,0
- push si
- view1:
- mov si,n
- add si,n
- sub si,2
- mov ax,word ptr[bx][si]
- add sumCol,ax
- add bx,n
- add bx,n
- pop si
- push bx
- lea bx,matrix
- mov ax,word ptr[bx][si]
- add sumRow,ax
- add si,2
- pop bx
- push si
- loop view1
- mov ax,sumCol
- write newline
- write msgSumCol
- OutputDigit
- mov ax,sumRow
- write newline
- write msgSumRow
- OutputDigit
- pop bx
- ENDM
- ; ????????? ?????????? ??????????? ??????????? ??????
- ; ????? : minSize ???????? ??????????? ???????????
- MinSizeF proc
- mov ax,n1
- mov minSize,ax
- IRPC it,<23>
- local lower,higher
- mov ax,n&it
- cmp minSize,ax
- ja lower
- jb higher
- lower: mov minSize,ax
- higher:
- ENDM
- ret
- MinSizeF endp
- start:
- mov ax,data
- mov ds,ax
- mov finalSum,0
- IRPC num,<123>
- write newline
- write msgEnterN
- InputDigit
- mov n&num,ax
- write newline
- write msgEl
- InputMatrix array&num,n&num
- OutputMatrix array&num,n&num
- FuncMatrix array&num,n&num
- mov ax,sumCol
- add finalSum,ax
- mov ax,sumRow
- add finalSum,ax
- ENDM
- call MinSizeF
- write newline
- write msgLowestSize
- mov ax,minSize
- OutputDigit
- write newline
- write msgFinalSum
- mov ax,finalSum
- OutputDigit
- write newline
- write newline
- write msgRes
- mov ax,finalSum
- mov bx,minSize
- mov dx,0
- div bx
- OutputDigit
- mov ax,4c00h
- int 21h
- code ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement