Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;переставить K и L строки
  2. .386
  3. assume CS:cseg, DS:dseg, SS:sseg
  4.  
  5. sseg segment stack use16
  6.     db 256 dup (?)
  7. sseg ends
  8.  
  9. dseg segment use16
  10.     arr dw 0h, 1h, 2h, 3h, 4h
  11.         dw 5h, 6h, 7h, 8h, 9h
  12.         dw 0Ah, 0Bh, 0Ch, 0Dh, 0Eh
  13.         dw 0Fh, 10h, 11h, 12h, 13h
  14.         dw 14h, 15h, 16h, 17h, 18h
  15.        
  16.     N dw 5
  17.     K dw 4
  18.     L dw 4
  19. dseg ends
  20.  
  21. cseg segment use16
  22.  
  23. include OutInt.inc
  24.  
  25. ; +0Ah j: second line to swap
  26. ; +8h  i: first line to swap
  27. ; +6h  N: size of array
  28. ; +4h  arr: pointer to array
  29. ; +2h  ret: ax = arr[i][j]
  30. index proc
  31.     push bp
  32.     mov bp, sp
  33.    
  34.     push bx
  35.     push dx
  36.    
  37.     ; ax = arr + N*(i * type arr) + (j * type arr)
  38.     mov ax, [bp+8h] ; ax = i
  39.     shl ax, 1       ; ax = (i * type arr)
  40.     mov bx, [bp+6h] ; bx = N
  41.     mul bx          ; ax = (i* type arr)*N
  42.     mov bx, [bp+0Ah]; bx = j
  43.     shl bx, 1       ; bx = (j * type arr)
  44.     add ax, bx      ; ax = i*(N * type arr) + (j * type arr)
  45.     add ax, [bp+4h] ; ax = arr + i*(N * type arr) + (j * type arr)
  46.    
  47.     pop dx
  48.     pop bx
  49.    
  50.     pop bp
  51.     ret 8h
  52. index endp
  53.  
  54. ; +0Ah L: second line to swap
  55. ; +8h  K: first line to swap
  56. ; +6h  N: size of array
  57. ; +4h  arr: pointer to array
  58. ; +2h  ret:  none, result in arr
  59. swap proc
  60.     push bp
  61.     mov bp, sp
  62.    
  63.     push ax
  64.     push bx
  65.     push cx
  66.     push si
  67.     push di
  68.    
  69.     ; si = arr + K*(N * type arr)
  70.     push 0       ; j
  71.     push WORD PTR [bp+8h] ; i
  72.     push WORD PTR [bp+6h] ; N
  73.     push WORD PTR [bp+4h] ; arr
  74.     call index
  75.     mov si, ax
  76.    
  77.     ; di = arr + L*(N * type arr)
  78.     push 0       ; j
  79.     push WORD PTR [bp+0Ah]; i
  80.     push WORD PTR [bp+6h] ; N
  81.     push WORD PTR [bp+4h] ; arr
  82.     call index
  83.     mov di, ax
  84.    
  85.     ; xchange L and K lines
  86.     mov cx, [bp+6h]
  87.     beg_cycle:
  88.         ; tmp = arr[K][i]
  89.         mov ax, [si]
  90.        
  91.         ; arr[K][cx] = arr[L][i]
  92.         mov bx, [di]
  93.         mov [si], bx
  94.        
  95.         ; arr[L][i] = tmp
  96.         mov [di], ax
  97.    
  98.         add si, 2
  99.         add di, 2
  100.         dec cx
  101.         jnz beg_cycle
  102.     end_cycle:
  103.    
  104.     pop di
  105.     pop si
  106.     pop cx
  107.     pop bx
  108.     pop ax
  109.    
  110.     pop bp
  111.     ret 8h
  112. swap endp
  113.  
  114. ; +6h N: size of array
  115. ; +4h arr: pointer to array
  116. ; +2h ret: none
  117. print proc
  118.     push bp
  119.     mov bp, sp
  120.    
  121.     push ax
  122.     push bx
  123.     push cx
  124.     push dx
  125.     push si
  126.    
  127.     mov si, [bp+4h]
  128.     xor cx, cx
  129.     cycle_i:
  130.         xor bx, bx
  131.         cycle_j:
  132.             push WORD PTR [si]
  133.             call OutInt
  134.            
  135.             mov ah, 2h
  136.             mov dl, ' '
  137.             int 21h
  138.            
  139.             add si, 2
  140.             inc bx
  141.             cmp bx, [bp+6h]
  142.             jnz cycle_j
  143.         end_cycle_j:
  144.        
  145.         mov ah, 2h
  146.         mov dl, 0Ah
  147.         int 21h
  148.        
  149.         inc cx
  150.         cmp cx, [bp+6h]
  151.         jnz cycle_i
  152.     end_cycle_i:
  153.    
  154.     pop si
  155.     pop dx
  156.     pop cx
  157.     pop bx
  158.     pop ax
  159.    
  160.     pop bp
  161.     ret 4h
  162. print endp
  163.  
  164. main:
  165.     mov ax, dseg
  166.     mov ds, ax
  167.    
  168.     push N
  169.     push offset arr
  170.     call print
  171.    
  172.     mov ah, 2h
  173.     mov dl, 0Ah
  174.     int 21h
  175.    
  176.     push L
  177.     push K
  178.     push N
  179.     push offset arr
  180.     call swap
  181.    
  182.     push N
  183.     push offset arr
  184.     call print
  185.    
  186.     ;return to os
  187.     mov ax, 4c00h
  188.     int 21h
  189. cseg ends
  190.     end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement