< -->

;Rotoria!.asm
.model tiny
.code
org 100h
.386
Start:
        mov ax, 83h
        int 10h
        mov ax, 0B800h
        mov ds, ax
        mov es, ax
cycle_lp:
        mov bx, 22*2*80
nextZ_:
        push bx
        call dblrotZ1
        pop bx
        sub bx, 2*2*80
        push bx
        call dblrotZ2
        pop bx
        sub bx, 2*2*80
        jns nextZ_
        mov bx, 25*2*80-2
        push ax
        pop word ptr [bx]

	mov ah, 86h
	mov cx, 2
	mov dx, 65000
	int 15h

	mov bx, 2*80-4
next_:
	push bx
        call dblrot1
	pop bx
	sub bx, 4
	push bx
        call dblrot2
	pop bx
	sub bx, 4
	jns next_

	mov ah, 86h
	mov cx, 2
	mov dx, 65000
	int 15h
	mov ah, 0Bh
	int 21h
	test al, al
	je cycle_lp
        ret

dblrot1 proc near
  ;Вход: [bx] - 1-й эл-т;

        add bx, 24*2*80
	push word ptr [bx-2*80+2]
	push word ptr [bx+2]
	push word ptr [bx]
	push word ptr [bx-2*80]
	pop word ptr [bx]
	pop word ptr [bx+2]
	mov cx, 23
lp1:
	sub bx, 2*80
	push word ptr [bx-2*80]
	pop word ptr [bx]
	pop word ptr [bx+2]
	pop ax
;Теперь в стеке ничего нет
	push word ptr [bx-2*80+2]
	push ax
	loop lp1
	sub bx, 2*80
	pop word ptr [bx+2]	
	pop word ptr [bx]
        ret
dblrot1 endp

dblrot2 proc near
  ;Вход: [bx] - 1-й эл-т;

        add bx, 24*2*80
	push word ptr [bx-2*80]
	push word ptr [bx]
	push word ptr [bx+2]
	push word ptr [bx-2*80+2]
	pop word ptr [bx+2]
	pop word ptr [bx]
	mov cx, 23
lp2:
	sub bx, 2*80
	push word ptr [bx-2*80+2]
	pop word ptr [bx+2]
	pop word ptr [bx]
	pop ax
;Теперь в стеке ничего нет
	push word ptr [bx-2*80]
	push ax
	loop lp2
	sub bx, 2*80
	pop word ptr [bx]	
	pop word ptr [bx+2]
        ret
dblrot2 endp

dblrotZ1 proc near
;Вход: [bx] - 1-й эл-т;
;      ax-последний
;Выход: ax - 1-й эл-т;
	push word ptr [bx]
	mov cx, 80
	mov si, bx
        add si, 2
	mov di, bx
	cld
	rep movsw
	add bx, 2*2*80-2        ;последний эл.
	push word ptr [bx]
	mov cx, 80
	mov si, bx
        sub si, 2
	mov di, bx
	std
	rep movsw
	sub bx, 2*80
	pop word ptr [bx];Элемент снизу
        add bx, 2
        pop word ptr [bx]
        ret
dblrotZ1 endp

dblrotZ2 proc near
;Вход: [bx] - 1-й эл-т;
;      ax-последний
;Выход: ax - 1-й эл-т;
	add bx, 2*80-2
	push word ptr [bx]
	mov cx, 80
	mov si, bx
        sub si, 2
	mov di, bx
	std
	rep movsw
	add bx, 2        ;последний эл.
	push word ptr [bx]
	mov cx, 80
	mov si, bx
        add si, 2
	mov di, bx
	cld
	rep movsw
	sub bx, 2*80
	pop word ptr [bx];Элемент снизу
        add bx, 2*2*80-2
        pop word ptr [bx]
        ret
dblrotZ2 endp
end Start

Назад