������� �� ���������� (ASM)
 

��������� � �������� - ����� ������ ����� �� �����

������:
������� ��� ����� � ��������� ������� �� �����

�����:
� ���������� ���������, ������� ������ 3-� ����� � ������� ������� X*Y+Z, ����� ����� ��������� ���������. ����� ��� ����� ��� �������. ����� ��������� �� ��������.
;tasm prog
;tlink prog /t
;MASM;IDEAL or MASM
.MODEL tiny
.186
.CODE;SEG
org	100h
start:
;�������� � 3-�� ����� � ������ �����
		mov	ax,3
		int	10h
;����������, ��� ������� � ���������
		mov	si,10
;������ X
		call	isEnter
;���������� � �����
		push	di
;������ Y
		call	isEnter
;��������� �� ����� ����� � ��
		pop	ax
;�������� AX(X) � DI(Y)
		xor	dx,dx
		mul	di
;���������� � ����� ���������
		push	ax
;������ Z
		call	isEnter
;��������� �� ����� AX(X)*DI(Y)
		pop	ax
;���������
		add	ax,di
;����� �������� 5-���
		mov	cx,5
;���������� � ����� ����� � ������� �����
outLoop:	push	cx
		push	ax
;������� ���������
		mov	ah,9
		mov	dx,offset dbResult
		int	21h
;�������������� � ����� ���������� �����
		pop	ax
		push	ax
;���������� ������� ����
		xor	cx,cx
;����� �� 10
isDiv:		xor	dx,dx
		div	si
;���������� � ����� ������� �� ������� � ������� ���-�� ���� � �����
		push	dx
		inc	cx
;��������� ���� �� �������� 0
		or	ax,ax
		jnz	isDiv
;��������� �� ����� ����� � ������ �������
isOut:		pop	ax
;��������� ����� � ������ � ������� �� ����� � �����
		or	al,30h
		int	29h
		loop	isOut
;�������������� ����� � ������� �����
		pop	ax
		pop	cx
		loop	outLoop
;�������� �������
		xor	ax,ax
		int	16h
		ret
;
dbResult	db	13,10,'Result:$'
dbEnter		db	13,10,'Enter '
dbVal		db	'W:$'
;�������� ����������
isEnter:	inc	byte ptr[dbVal]
;������� ���������
		mov	ah,09
		mov	dx,offset dbEnter
		int	21h
;� ���� �������� ����� ������������ �����
		xor	di,di
;������ ��� ���
noNumber:	xor	ax,ax
		int	16h
;���� ENTER -���� ����� ��������
		cmp	al,13
		jz	isStop
;��� ��� �� ����� ����������
		cmp	al,'0'
		jb	noNumber
		cmp	al,'9'
		ja	noNumber
;������� �����
		int	29h
;��������������� � �����
		and	ax,0fh
;������ ������� ����� � ������ ��������� �����
		xchg	ax,di
;�������� ����� ��������� �� 10
		xor	dx,dx
		mul	si
;���������
		add	di,ax
		jmp	short noNumber
;����� �� �\�
isStop:		ret
	end	start
������ ������������ ������ �� ����� ������ �����.
LOCALS

data SEGMENT

data ENDS


ASSUME cs:code, ds:data, ss:stk

.186

code SEGMENT
entry_point:
mov ax,SEG data
mov ds,ax

mov ax,0003h	;��������� ���������� 80x25
INT 10h

;����������� ������������� ���
;0000h = 0
push 0		;Y
push 0		;X
push 0		;signed_flag
push 0000h	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

;����������� ������������� ���
;0FFFFh = 65535
push 0		;Y
push 10		;X
push 0		;signed_flag
push 0FFFFh	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)


;�������� ������������� ���
;8000h = -32768
push 1		;Y
push 0		;X
push 1		;signed_flag
push 8000h	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

;�������� ������������� ���
;7FFFh = 32767
push 1		;Y
push 10		;X
push 1		;signed_flag
push 7FFFh	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

;�������� ������������� ���
;0FFFFh = -1
push 1		;Y
push 20		;X
push 1		;signed_flag
push 0FFFFh	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)


push 4		;Y
push 1		;X
push 1		;signed_flag
push -13		;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

push 5		;Y
push 1		;X
push 1		;signed_flag
push -12345	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

push 6		;Y
push 1		;X
push 1		;signed_flag
push -31000	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

push 8		;Y
push 1		;X
push 1		;signed_flag
push +13		;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

push 9		;Y
push 1		;X
push 1		;signed_flag
push +12345	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

push 10		;Y
push 1		;X
push 1		;signed_flag
push +31000	;word_value
call PrintWord	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)


mov ah,0
INT 16h


mov ax,4C00h
INT 21h




const_PrintWord_return_code__success		= 0
const_PrintWord_return_code__X_is_too_big	= 1
const_PrintWord_return_code__Y_is_too_big	= 2

PrintWord	PROC	;(word_value:WORD, signed_flag:BYTE, X:BYTE, Y:BYTE)

		;�������: ax = ��� ����������

ARG @@word_value:WORD, @@signed_flag:BYTE, @@X:BYTE, @@Y:BYTE = @@arg_size
LOCAL @@dec_buf:BYTE:6 = @@local_size
push bp
mov bp,sp
sub sp,@@local_size

push ds
push es
push si
push di
push bx
push cx
push dx

;�������� X
mov al,@@X
cmp al,79
jbe @@X_is_OK

mov ax,const_PrintWord_return_code__X_is_too_big
jmp @@exit

@@X_is_OK:
;�������� Y
mov al,@@Y
cmp al,24
jbe @@Y_is_OK

mov ax,const_PrintWord_return_code__Y_is_too_big
jmp @@exit

@@Y_is_OK:
;�������� ���� ������
mov al,@@signed_flag
test al,al
jz process_word		;����������� ������������� ���

;�������� ���
test @@word_value,8000h
jz signed_positive

;�������� �������������
neg @@word_value
mov BYTE PTR @@dec_buf,'-'
jmp process_word

signed_positive:
;�������� �������������
mov BYTE PTR @@dec_buf,'+'


process_word:
mov ax,@@word_value
xor dx,dx
mov cx,5
mov bx,10
lea di,@@dec_buf
add di,6-1

div_10_loop:
	div bx
	or dl,'0'
	mov ss:[di],dl
	xor dx,dx
	dec di
	dec cx
	test cx,cx
	jnz div_10_loop

mov ax,0B800h
mov es,ax
mov ax,ss
mov ds,ax
lea si,@@dec_buf
mov cx,6

mov al,@@signed_flag
test al,al
jnz print_word_value

;����������� ������������� ���
inc si
dec cx

print_word_value:
mov al,@@Y
mov ah,80
mul ah
mov dl,@@X
xor dh,dh
add ax,dx
shl ax,1
mov di,ax

print_loop:
	mov al,ds:[si]
	mov es:[di],al
	inc si
	inc di
	inc di

	dec cx
	test cx,cx
	jnz print_loop

mov ax,const_PrintWord_return_code__success

@@exit:
pop dx
pop cx
pop bx
pop di
pop si
pop es
pop ds

mov sp,bp
pop bp
ret @@arg_size
PrintWord	ENDP



code ENDS

stk SEGMENT PARA STACK
DB 200h DUP(?)
stk ENDS

END entry_point

   �����
   ����������