Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;переставить K и L строки
- .386
- assume CS:cseg, DS:dseg, SS:sseg
- sseg segment stack use16
- db 256 dup (?)
- sseg ends
- dseg segment use16
- arr dw 0h, 1h, 2h, 3h, 4h
- dw 5h, 6h, 7h, 8h, 9h
- dw 0Ah, 0Bh, 0Ch, 0Dh, 0Eh
- dw 0Fh, 10h, 11h, 12h, 13h
- dw 14h, 15h, 16h, 17h, 18h
- N dw 5
- K dw 4
- L dw 4
- dseg ends
- cseg segment use16
- include OutInt.inc
- ; +0Ah j: second line to swap
- ; +8h i: first line to swap
- ; +6h N: size of array
- ; +4h arr: pointer to array
- ; +2h ret: ax = arr[i][j]
- index proc
- push bp
- mov bp, sp
- push bx
- push dx
- ; ax = arr + N*(i * type arr) + (j * type arr)
- mov ax, [bp+8h] ; ax = i
- shl ax, 1 ; ax = (i * type arr)
- mov bx, [bp+6h] ; bx = N
- mul bx ; ax = (i* type arr)*N
- mov bx, [bp+0Ah]; bx = j
- shl bx, 1 ; bx = (j * type arr)
- add ax, bx ; ax = i*(N * type arr) + (j * type arr)
- add ax, [bp+4h] ; ax = arr + i*(N * type arr) + (j * type arr)
- pop dx
- pop bx
- pop bp
- ret 8h
- index endp
- ; +0Ah L: second line to swap
- ; +8h K: first line to swap
- ; +6h N: size of array
- ; +4h arr: pointer to array
- ; +2h ret: none, result in arr
- swap proc
- push bp
- mov bp, sp
- push ax
- push bx
- push cx
- push si
- push di
- ; si = arr + K*(N * type arr)
- push 0 ; j
- push WORD PTR [bp+8h] ; i
- push WORD PTR [bp+6h] ; N
- push WORD PTR [bp+4h] ; arr
- call index
- mov si, ax
- ; di = arr + L*(N * type arr)
- push 0 ; j
- push WORD PTR [bp+0Ah]; i
- push WORD PTR [bp+6h] ; N
- push WORD PTR [bp+4h] ; arr
- call index
- mov di, ax
- ; xchange L and K lines
- mov cx, [bp+6h]
- beg_cycle:
- ; tmp = arr[K][i]
- mov ax, [si]
- ; arr[K][cx] = arr[L][i]
- mov bx, [di]
- mov [si], bx
- ; arr[L][i] = tmp
- mov [di], ax
- add si, 2
- add di, 2
- dec cx
- jnz beg_cycle
- end_cycle:
- pop di
- pop si
- pop cx
- pop bx
- pop ax
- pop bp
- ret 8h
- swap endp
- ; +6h N: size of array
- ; +4h arr: pointer to array
- ; +2h ret: none
- print proc
- push bp
- mov bp, sp
- push ax
- push bx
- push cx
- push dx
- push si
- mov si, [bp+4h]
- xor cx, cx
- cycle_i:
- xor bx, bx
- cycle_j:
- push WORD PTR [si]
- call OutInt
- mov ah, 2h
- mov dl, ' '
- int 21h
- add si, 2
- inc bx
- cmp bx, [bp+6h]
- jnz cycle_j
- end_cycle_j:
- mov ah, 2h
- mov dl, 0Ah
- int 21h
- inc cx
- cmp cx, [bp+6h]
- jnz cycle_i
- end_cycle_i:
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- ret 4h
- print endp
- main:
- mov ax, dseg
- mov ds, ax
- push N
- push offset arr
- call print
- mov ah, 2h
- mov dl, 0Ah
- int 21h
- push L
- push K
- push N
- push offset arr
- call swap
- push N
- push offset arr
- call print
- ;return to os
- mov ax, 4c00h
- int 21h
- cseg ends
- end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement