- ( , ) .
. , : <>:=<>*10+<>.
: 10 . .
, .
.
n . , c , - . . "-".
.
Title inout
Code segment
assume cs:code, ds:code
N equ 5;
A dw N dup (?);
main proc far;
push ds; MS DOS
Mov ax, 0
Push ax
mov ax, code;
mov ds, ax; DS
call input;
call output;
ret; DOS
main endp;
input proc near;
mov cx, N;
mov di, 0;
cycl1_in: push cx;
lea dx, mes_in;
mov ah, 9; DOS
int 21h;
lea dx, BUf_in;
mov ah, 0ah; DOS
int 21h;
mov byte ptr NEG_IN, 0; - " "
cld; - " "
mov cl, BUF_IN+1;
mov ch, 0; - CX
lea si, BUF_IN+2;
cmp byte ptr [si], '-'; ?
jne short unsigned; ,
mov byte ptr NEG_IN, 1; - " "
inc si;
dec cx;
unsigned: mov bx, 0;
cycl2_in: mov ax, 10; 10
mul bx; 10
|
|
mov bx, ax; BX
lodsb;
sub al, 30h;
cbw;
add bx, ax;
loop cycl2_in;
cmp NEG_IN, 0; ?
je short done; ,
neg bx;
done: mov A[di], bx;
add di, 2;
pop cx;
loop cycl1_in;
ret;
BUF_IN db 10,10 dup (0); ( 10 )
NEG_IN db 0; "/"
mes_in db 13,10,' : $';
Input endp
output proc near;
lea dx, mes_out;
mov ah, 9; DOS
int 21h;
mov cx, N;
mov si, 0;
mov di, 7;
cycl1_out: mov byte ptr NEGOUT, 0; - " "
mov bx, 10; 10
mov ax, A[si];
cmp ax, 0;
jge short again; ,
mov byte ptr NEG_OUT, 1; " "
neg ax;
again: cwd;
div bx; 10
add dl, 30h;
mov BUF_OUT[di], dl;
dec di; 1
cmp ax, 0;
jne again; ,
cmp byte ptr NEG_OUT, 1;
jne short positive; ,
mov BUF_OUT[di], '-'; , "-"
positive: mov ax, N+2;
sub ax, cx;
mov bx, 7;
mul bx;
mov di, ax; DI
add si, 2;
loop cycl1_out;
lea dx, BUF_OUT;
mov ah, 9; DOS
int 21h;
ret;
NEG_OUT db 0; "/"
BUF_OUT db 13,10, N*7 dup (' '),'$';
mes_out db 13,10,': $';
Output endp
Code ends
End main