Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. title   laba
  2.         assume  cs:c, ds:d, ss:s
  3.  
  4. s       segment stack
  5.         dw      256 dup (?)
  6. s       ends
  7.  
  8.         ;символы возврата каретки и перевода строки
  9.         cr = 0dh
  10.         lf = 0ah
  11.  
  12. d       segment
  13. A       dw 10 dup (10 dup (0))
  14. N       dw      ?
  15. M       dw      ?
  16.  
  17. msgarr  db      'Enter elements matrix: $'
  18. msga    db      'Matrix A:', cr, lf, '$'
  19. msgn    db      'Enter N: $'
  20. msgm    db      'Enter M: $'
  21. crlf    db      cr, lf, '$'
  22. space   db      ' $'
  23. ;описываем данные процедуры ввода числа
  24. string  db      255, 0, 255 dup (?)
  25. errmsg1 db      'Invalid character, you can use '
  26.         db      'the first character can be '
  27.         db      'mark + or -', cr, lf, '$'
  28. errmsg2 db      'Invalid character, you can use '
  29.         db      'only numbers', cr, lf, '$'
  30. errmsg3 db      'Overflow detected! '
  31.         db      'Please try again.', cr, lf, '$'
  32. negflag dw      ?
  33. d       ends
  34.  
  35. ;описываем макрокоманду вывода текстовой строки
  36. PRINT   macro   STR
  37.         push    ax
  38.         push    dx
  39.         mov     ah,9
  40.         lea     dx,STR
  41.         int     21h
  42.         pop     dx
  43.         pop     ax
  44.         endm
  45.  
  46. c       segment
  47. ;описываем процедуру ввода целого числа в регистр ax
  48. IntegerIn       proc
  49.             im: push    bx
  50.                 push    dx
  51.                 push    si
  52.                 mov     ah, 0ah
  53.                 lea     dx, string
  54.                 int     21h
  55.                 xor     ax, ax
  56.                 lea     si, string+2
  57.                 mov     negflag, ax
  58.                 cmp     byte ptr [si], '-'
  59.                 jne     im2
  60.                 not     negflag
  61.                 inc     si
  62.                 jmp     im1
  63. im2:            cmp     byte ptr [si], '+'
  64.                 jne     im1
  65.                 inc     si
  66. im1:            cmp     byte ptr [si], cr
  67.                 je      iex1
  68.                 cmp     byte ptr [si], '0'
  69.                 jb      ierr1
  70.                 cmp     byte ptr [si], '9'
  71.                 ja      ierr1
  72.                 mov     bx, 10
  73.                 mul     bx
  74.                 jo      ierr2;
  75.                 sub     byte ptr [si], '0'
  76.                 add     al, [si]
  77.                 jo      ierr2
  78.                 adc     ah,0
  79.                 jo      ierr2
  80.                 inc     si
  81.                 jmp     im1
  82. ierr1:          print   crlf
  83.                 print   errmsg1
  84.                 jmp     im
  85. ierr2:          print   crlf
  86.                 print   errmsg3
  87.                 jmp     im
  88. iex1:           cmp     negflag, 0
  89.                 jne     cmp1
  90.                 cmp     ax,32767
  91.                 ja      ierr2
  92.                 jmp     iex
  93. cmp1:           cmp     ax,32768
  94.                 ja      ierr2
  95.                 neg     ax
  96. iex:            pop     si
  97.                 pop     dx
  98.                 pop     bx
  99.                 ret
  100. IntegerIn       endp
  101.  
  102. ;описываем процедуру ввода беззнакового числа в регистр ax
  103. UnsignedIn      proc
  104. um:             push    bx
  105.                 push    dx
  106.                 push    si
  107.                 mov     ah,0ah
  108.                 lea     dx,string
  109.                 int     21h
  110.                 xor     ax,ax
  111.                 lea     si,string+2
  112. um1:            cmp     byte ptr [si],cr
  113.                 je      uex
  114.                 cmp     byte ptr [si], '0'
  115.                 jb      uerr1
  116.                 cmp     byte ptr [si], '9'
  117.                 ja      uerr1
  118.                 mov     bx,10
  119.                 mul     bx
  120.                 jc      uerr2
  121.                 sub     byte ptr [si], '0'
  122.                 add     al, [si]
  123.                 jc      uerr2
  124.                 adc     ah,0
  125.                 jc      uerr2
  126.                 inc     si
  127.                 jmp     um1
  128. uerr1:          print   crlf
  129.                 print   errmsg2
  130.                 jmp     um
  131. uerr2:          print   crlf
  132.                 print   errmsg3
  133.                 jmp     um
  134. uex:            pop     si
  135.                 pop     dx
  136.                 pop     bx
  137.                 ret
  138. UnsignedIn      endp
  139.  
  140. ;описываем процедуру вывода целого числа из регистра ax
  141. IntegerOut      proc
  142.                 push    ax
  143.                 push    bx
  144.                 push    cx
  145.                 push    dx
  146.                 push    si
  147.                 push    di
  148.                 xor     cx, cx
  149.                 mov     bx, 10
  150.                 cmp     ax, 0
  151.                 jge     om
  152.                 neg     ax
  153.                 push    ax
  154.                 mov     ah, 2
  155.                 mov     dl, '-'
  156.                 int     21h
  157.                 pop     ax
  158. om:             inc     cx
  159.                 xor     dx, dx
  160.                 div     bx
  161.                 push    dx
  162.                 or      ax, ax
  163.                 jnz     om
  164. om1:            pop     dx
  165.                 add     dx, '0'
  166.                 mov     ah, 2
  167.                 int     21h
  168.                 loop    om1
  169.                 pop     di
  170.                 pop     si
  171.                 pop     dx
  172.                 pop     cx
  173.                 pop     bx
  174.                 pop     ax
  175.                 ret
  176. IntegerOut      endp
  177.  
  178. start:          mov     ax,d
  179.                 mov     ds,ax
  180.  r:             print   crlf
  181.                 print   msgm
  182.                 call   UnsignedIn
  183.                 cmp    ax,0
  184.                 je     r
  185.                 mov    M,ax
  186.  r1:            print   crlf
  187.                 print  msgn
  188.                 call   UnsignedIn
  189.                 cmp    ax,1
  190.                 jbe    r1
  191.                 mov    N,ax
  192.                 print  crlf
  193.                 print  msgarr
  194.                 print  crlf
  195.                
  196.                 mov    cx,M
  197.                 xor    bx,bx
  198. n1:            push    cx
  199.                 mov    cx,N
  200.                 xor si,si
  201. nt:             push si
  202.                 push cx
  203.                 push bx
  204.                 call   IntegerIn
  205.                 pop bx
  206.                 pop cx
  207.                 pop si  
  208.                 mov    A[bx+si],ax
  209.                 add    si,2
  210.                 print crlf
  211.                 loop   nt
  212.                 pop cx
  213.                 add bx,10*2
  214.                 loop   n1
  215.    
  216.  
  217.         print   msga   
  218.         mov cx,M
  219.         xor bx,bx
  220. sm2:    push    cx
  221.         mov cx,N
  222.         xor si,si
  223. sm3:    mov ax,A[bx+si]
  224.         call    IntegerOut
  225.         print   space
  226.         add si,2
  227.         loop    sm3
  228.         pop cx
  229.         add bx,10*2
  230.         print   crlf
  231.         loop    sm2
  232.        
  233.         ;max
  234.         mov ax,a[0]
  235.         mov cx,M
  236.         xor bx,bx
  237.         mov ax,a[0]
  238.         xor bp,bp
  239. smmm2:  push cx
  240.         mov cx,N
  241.         xor si,si
  242. smmm3:  cmp ax,A[bx+si]
  243.         jbe m11
  244.         mov ax,A[bx+si]
  245.         mov bp,bx
  246. m11:    add si,2
  247.         loop    smmm3
  248.         pop cx
  249.         add bx,10*2
  250.         print   crlf
  251.         loop    smmm2
  252.         ;call IntegerOut
  253.        
  254.         mov ax,a[0]
  255.         mov cx,M
  256.         xor bx,bx
  257.         xor dx,dx
  258. smm2:   push cx
  259.         mov cx,N
  260.         xor si,si
  261. smm3:   cmp ax,A[bx+si]
  262.         jge m1
  263.         mov ax,A[bx+si]
  264.         mov dx,bx
  265. m1:     add si,2
  266.         loop    smm3
  267.         pop cx
  268.         add bx,10*2
  269.         print   crlf
  270.         loop    smm2
  271. push dx
  272. pop bx
  273.         mov cx,N
  274.         xor si,si
  275. km2:    mov dx, A[bp+si]
  276.         mov ax, A[bx+si]
  277.         mov A[bp+si], ax
  278.         mov A[bx+si],dx
  279.         add si,2
  280.         loop km2
  281.        
  282.         print   msga   
  283.         mov cx,M
  284.         xor bx,bx
  285. nm2:    push cx
  286.         mov cx,N
  287.         xor si,si
  288. nm3:    mov ax,A[bx+si]
  289.         call    IntegerOut
  290.         print   space
  291.         add si,2
  292.         loop    nm3
  293.         pop cx
  294.         add bx,10*2
  295.         print   crlf
  296.         loop    nm2
  297.        
  298. ex:             mov     ah,4ch
  299.                 int     21H
  300. c               ends
  301.                 end     start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement