 |
- , ,
- :
- tasm : 7 , , , .
- :
-
:
3500: 1
3500: 2
3500: 100
3500: -200
3500: -100
3500: 500
3500: 1000
1 2 100 -200 -100 500 1000
Summ = 1303
Press any key ...
; -
.model tiny
.code
;
LOCALS @@ ; , @@ . .
JUMPS ; , 128
StdOut equ 1 ;
org 100h
start:
mov ax, 3
int 10h
lea si, array ;
mov cx, 7
@@next_number:
lea dx, msg_prompt
mov ah, 9
int 21h
mov WORD PTR f_handle, StdOut
CALL inputWord_signed
mov [si], ax
add si, 2
LOOP @@next_number
;
mov al, 13 ;
CALL WriteChar_to_file
mov al, 10
CALL WriteChar_to_file
lea si, array
mov cx, 7
@@next_screen:
mov ax, [si]
add summ, ax
CALL WriteWordDEC_signed
mov al, ' ' ;
CALL WriteChar_to_file
CALL WriteChar_to_file
add si, 2
LOOP @@next_screen
lea dx, msg_summ
mov ah, 9
int 21h
mov ax, summ
CALL WriteWordDEC_signed
;
lea dx, outFileName
mov ah, 3Ch ;
mov cx, 20h ;
int 21h
jc @@_file_error ; -
mov f_handle, ax ;
lea si, array
mov cx, 7
@@next_to_file:
mov ax, [si]
add summ, ax
CALL WriteWordDEC_signed
mov al, ' ' ;
CALL WriteChar_to_file
CALL WriteChar_to_file
add si, 2
LOOP @@next_to_file
lea si, msg_summ
@@_msg_to_file:
mov al, [si]
cmp al, '$'
je @@_summ_to_file
CALL WriteChar_to_file
inc si
jmp @@_msg_to_file
@@_summ_to_file:
mov ax, summ
CALL WriteWordDEC_signed
jmp @@exit
@@_file_error:
lea dx, msg_fileError
mov ah, 9
int 21h
@@exit:
;
mov bx, f_handle
cmp bx, 1
je @@_no_file
mov ah,3Eh ;
int 21h
@@_no_file:
lea dx, PressKey
mov ah,9
int 21h
xor ax, ax
int 16h
int 20h
inputWord_signed proc
; - AX
; ,
push bx
push cx
push dx
push si ;
push di ; 0,
mov cx, StdOut ; f_handle
mov f_handle, cx
xor si, si
xor di, di
mov bx, 10
@@1:
mov ah, 7
int 21h ;
xor ah, ah
cmp al, '-'
jne @@2
CALL WriteChar_to_file ;
inc di ;
jmp @@_next_char ;
@@2:
cmp al, 13 ; ENTER =
je @@_finish
cmp al, '0'
jb @@_next_char
cmp al, '9'
ja @@_next_char
mov cl, al ; ,
sub al, '0' ;
or si, si ; ?
jnz @@_not_new ; 0, -
@@_not_zerou:
mov si, ax
or di, di
jz @@_positive
neg si
@@_positive:
mov al, cl
CALL WriteChar_to_file
jmp @@_next_char
@@_not_new:
push ax
; 10
mov ax, si
imul bx ;
jc @@_finish ; =
mov di, ax ; dx
mov al, cl
CALL WriteChar_to_file
pop ax
or di, di
jns @@_add
sub di, ax
jo @@_finish
jmp @@_ok
@@_add:
add di, ax
jo @@_finish
@@_ok:
mov si, di ; = si
@@_next_char:
mov ah, 7
int 21h
xor ah, ah
jmp @@2
@@_finish:
mov ax, si ; AX
pop di
pop si
pop dx
pop cx
pop bx
ret
inputWord_signed endp
writeWordDEC proc near
; AX,
push ax
push bx
push dx
push cx
mov bx, 10
xor cx, cx
@@1:
xor dx, dx
div bx
push dx
inc cx
or ax, ax
jnz @@1
@@2:
pop ax
add al, '0'
CALL WriteChar_to_file
LOOP @@2
pop cx
pop dx
pop bx
pop ax
ret
writeWordDEC endp
WriteWordDEC_signed proc
; AX
push ax ; AX
or ax, ax
jns @@_no_sign
push ax ; ,
mov al, '-'
CALL writeChar_to_file
pop ax
neg ax ; +
@@_no_sign:
CALL writeWordDEC
pop ax
ret
WriteWordDEC_signed endp
; , f_handle
; AL
; f_handle
WriteChar_to_file proc
push ax
push bx
push cx
push dx
mov buf, al
mov ah, 40h
mov bx, f_handle
lea dx, buf
mov cx, 1
int 21h
pop dx
pop cx
pop bx
pop ax
ret
WriteChar_to_file endp
array dw 7 dup (?) ; 7
outFileName db '168041.txt',0 ; = ASCIIZ
msg_fileError db 13,10,' $'
f_Handle dw ? ; , , = 1
; 40h =
msg_summ db 13,10,'Summ = $'
summ dw 0 ;
buf db ?
msg_prompt db 13,10,' 3500: $' ;
PressKey db 13,10,'Press any key ...$'
end start
|  |