Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- title laba
- assume cs:c, ds:d, ss:s
- s segment stack
- dw 256 dup (?)
- s ends
- ;символы возврата каретки и перевода строки
- cr = 0dh
- lf = 0ah
- d segment
- A dw 10 dup (10 dup (0))
- N dw ?
- M dw ?
- msgarr db 'Enter elements matrix: $'
- msga db 'Matrix A:', cr, lf, '$'
- msgn db 'Enter N: $'
- msgm db 'Enter M: $'
- crlf db cr, lf, '$'
- space db ' $'
- ;описываем данные процедуры ввода числа
- string db 255, 0, 255 dup (?)
- errmsg1 db 'Invalid character, you can use '
- db 'the first character can be '
- db 'mark + or -', cr, lf, '$'
- errmsg2 db 'Invalid character, you can use '
- db 'only numbers', cr, lf, '$'
- errmsg3 db 'Overflow detected! '
- db 'Please try again.', cr, lf, '$'
- negflag dw ?
- d ends
- ;описываем макрокоманду вывода текстовой строки
- PRINT macro STR
- push ax
- push dx
- mov ah,9
- lea dx,STR
- int 21h
- pop dx
- pop ax
- endm
- c segment
- ;описываем процедуру ввода целого числа в регистр ax
- IntegerIn proc
- im: push bx
- push dx
- push si
- mov ah, 0ah
- lea dx, string
- int 21h
- xor ax, ax
- lea si, string+2
- mov negflag, ax
- cmp byte ptr [si], '-'
- jne im2
- not negflag
- inc si
- jmp im1
- im2: cmp byte ptr [si], '+'
- jne im1
- inc si
- im1: cmp byte ptr [si], cr
- je iex1
- cmp byte ptr [si], '0'
- jb ierr1
- cmp byte ptr [si], '9'
- ja ierr1
- mov bx, 10
- mul bx
- jo ierr2;
- sub byte ptr [si], '0'
- add al, [si]
- jo ierr2
- adc ah,0
- jo ierr2
- inc si
- jmp im1
- ierr1: print crlf
- print errmsg1
- jmp im
- ierr2: print crlf
- print errmsg3
- jmp im
- iex1: cmp negflag, 0
- jne cmp1
- cmp ax,32767
- ja ierr2
- jmp iex
- cmp1: cmp ax,32768
- ja ierr2
- neg ax
- iex: pop si
- pop dx
- pop bx
- ret
- IntegerIn endp
- ;описываем процедуру ввода беззнакового числа в регистр ax
- UnsignedIn proc
- um: push bx
- push dx
- push si
- mov ah,0ah
- lea dx,string
- int 21h
- xor ax,ax
- lea si,string+2
- um1: cmp byte ptr [si],cr
- je uex
- cmp byte ptr [si], '0'
- jb uerr1
- cmp byte ptr [si], '9'
- ja uerr1
- mov bx,10
- mul bx
- jc uerr2
- sub byte ptr [si], '0'
- add al, [si]
- jc uerr2
- adc ah,0
- jc uerr2
- inc si
- jmp um1
- uerr1: print crlf
- print errmsg2
- jmp um
- uerr2: print crlf
- print errmsg3
- jmp um
- uex: pop si
- pop dx
- pop bx
- ret
- UnsignedIn endp
- ;описываем процедуру вывода целого числа из регистра ax
- IntegerOut proc
- push ax
- push bx
- push cx
- push dx
- push si
- push di
- xor cx, cx
- mov bx, 10
- cmp ax, 0
- jge om
- neg ax
- push ax
- mov ah, 2
- mov dl, '-'
- int 21h
- pop ax
- om: inc cx
- xor dx, dx
- div bx
- push dx
- or ax, ax
- jnz om
- om1: pop dx
- add dx, '0'
- mov ah, 2
- int 21h
- loop om1
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- IntegerOut endp
- start: mov ax,d
- mov ds,ax
- r: print crlf
- print msgm
- call UnsignedIn
- cmp ax,0
- je r
- mov M,ax
- r1: print crlf
- print msgn
- call UnsignedIn
- cmp ax,1
- jbe r1
- mov N,ax
- print crlf
- print msgarr
- print crlf
- mov cx,M
- xor bx,bx
- n1: push cx
- mov cx,N
- xor si,si
- nt: push si
- push cx
- push bx
- call IntegerIn
- pop bx
- pop cx
- pop si
- mov A[bx+si],ax
- add si,2
- print crlf
- loop nt
- pop cx
- add bx,10*2
- loop n1
- print msga
- mov cx,M
- xor bx,bx
- sm2: push cx
- mov cx,N
- xor si,si
- sm3: mov ax,A[bx+si]
- call IntegerOut
- print space
- add si,2
- loop sm3
- pop cx
- add bx,10*2
- print crlf
- loop sm2
- ;max
- mov ax,a[0]
- mov cx,M
- xor bx,bx
- mov ax,a[0]
- xor bp,bp
- smmm2: push cx
- mov cx,N
- xor si,si
- smmm3: cmp ax,A[bx+si]
- jbe m11
- mov ax,A[bx+si]
- mov bp,bx
- m11: add si,2
- loop smmm3
- pop cx
- add bx,10*2
- print crlf
- loop smmm2
- ;call IntegerOut
- mov ax,a[0]
- mov cx,M
- xor bx,bx
- xor dx,dx
- smm2: push cx
- mov cx,N
- xor si,si
- smm3: cmp ax,A[bx+si]
- jge m1
- mov ax,A[bx+si]
- mov dx,bx
- m1: add si,2
- loop smm3
- pop cx
- add bx,10*2
- print crlf
- loop smm2
- push dx
- pop bx
- mov cx,N
- xor si,si
- km2: mov dx, A[bp+si]
- mov ax, A[bx+si]
- mov A[bp+si], ax
- mov A[bx+si],dx
- add si,2
- loop km2
- print msga
- mov cx,M
- xor bx,bx
- nm2: push cx
- mov cx,N
- xor si,si
- nm3: mov ax,A[bx+si]
- call IntegerOut
- print space
- add si,2
- loop nm3
- pop cx
- add bx,10*2
- print crlf
- loop nm2
- ex: mov ah,4ch
- int 21H
- c ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement