Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; multi-segment executable file template.
- data segment
- ; add your data here!
- PromtInfo db "Enter the number of elements in array $"
- PromtInfo2 db "Invers array = $"
- PromtInfo3 db "Summ = $"
- PromptN db 'N=', '$'
- PromptA1 db 'A[', '$'
- PromptA2 db ']=', '$'
- kbdBuffer db 6, 0, 6 dup(0)
- CrLf db 0Dh, 0Ah, '$'
- N dw ? ;?????? ???????
- A dw 10 dup (0)
- inversA dw 10 dup (0)
- ends
- code segment
- assume cs:code,ds:data
- begin:
- ; set segment registers:
- mov ax, data
- mov ds, ax
- lea dx, PromtInfo
- mov ah, 9
- int 21h
- mov ah, 09h
- lea dx, CrLf
- int 21h
- ;-----------------------------------------
- Input_N:
- mov ah,09h
- lea dx, PromptN
- int 21h
- mov ah, 0Ah
- lea dx, kbdBuffer
- int 21h
- mov ah, 09h
- lea dx, CrLf
- int 21h
- lea si, kbdBuffer+1
- lea di, N
- call Str2Num
- ;---------------------------------------------
- ;???? ???????
- Input_Arr:
- mov cx, N
- lea dx, A
- call InputArray
- ;--------------------------------
- lea dx, PromtInfo2
- mov ah, 9
- int 21h
- mov cx , N
- lea si , A
- mov bx , 0
- add si, cx
- add si, cx
- OutPutArr:
- sub si, 2
- mov ax, [si]
- add bx , ax
- call Show_AX
- mov ah, 02h
- mov dl, ' '
- int 21h
- loop OutPutArr
- mov ah,09h ;??????? ?????? (?? ????? ??????)
- lea dx, CrLf
- int 21h
- lea dx, PromtInfo3
- mov ah, 9
- int 21h
- mov ax,bx
- call Show_AX
- ;lea dx, pkey
- ;mov ah, 9
- ;int 21h ; output string at ds:dx
- ; wait for any key....
- mov ah, 1
- int 21h
- mov ax, 4c00h ; exit to operating system.
- int 21h
- Str2Num proc
- push ax
- push bx
- push cx
- push dx
- push ds
- push es
- push si
- push ds
- pop es
- mov cl, ds:[si]
- xor ch, ch
- inc si
- cmp [si], byte ptr '-'
- jne @@IsPositive
- inc si
- dec cx
- @@IsPositive:
- jcxz @@Error
- mov bx, 10
- xor ax, ax
- @@Loop:
- mul bx ; ???????? ax ?? 10 ( dx:ax=ax*bx )
- mov [di], ax ; ?????????? ??????? ?????
- cmp dx, 0 ; ?????????, ????????? ?? ????????????
- jnz @@Error
- mov al, [si] ; ??????????? ????????? ?????? ? ?????
- cmp al, '0'
- jb @@Error
- cmp al, '9'
- ja @@Error
- sub al, '0'
- xor ah, ah
- add ax, [di]
- jc @@Error ; ???? ????? ?????? 65535
- inc si
- loop @@Loop
- pop si
- push si
- or ax, ax
- js @@Error
- cmp [si+1], byte ptr '-'
- jne @@Positive
- neg ax
- or ax, ax
- jns @@Error
- @@Positive:
- mov [di], ax
- clc
- pop si
- pop es
- pop ds
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- @@Error:
- xor ax, ax
- mov [di], ax
- stc
- pop si
- pop es
- pop ds
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- Str2Num endp
- ; ??????? ????? ?? ???????? AX ?? ?????
- ; ??????? ??????:
- ; ax - ????? ??? ???????????
- Show_AX proc
- push ax
- push bx
- push cx
- push dx
- push di
- mov cx, 10 ; cx - ????????? ??????? ?????????
- xor di, di ; di - ???. ???? ? ?????
- ; ???? ????? ? ax ?????????????, ??
- ;1) ?????????? '-'
- ;2) ??????? ax ?????????????
- or ax, ax
- jns @@Conv
- push ax
- mov dx, '-'
- mov ah, 2 ; ah - ??????? ?????? ??????? ?? ?????
- int 21h
- pop ax
- neg ax
- @@Conv:
- xor dx, dx
- div cx ; dl = num mod 10
- add dl, '0' ; ??????? ? ?????????? ??????
- inc di
- push dx ; ?????????? ? ????
- or ax, ax
- jnz @@Conv
- ; ??????? ?? ????? ?? ?????
- @@Show:
- pop dx ; dl = ????????? ??????
- mov ah, 2 ; ah - ??????? ?????? ??????? ?? ?????
- int 21h
- dec di ; ????????? ???? di<>0
- jnz @@Show
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- Show_AX endp
- ;???? ???????
- ;cx - ?????????? ???????? ?????????
- ;ds:dx - ????? ???????
- InputArray proc
- push ax
- push bx
- push cx
- push dx
- push si
- push di
- jcxz @@Exit ;???? ?????? ?????? - ?????????
- mov si, 1 ;?????? ???????? ???????
- mov di, dx ;????? ???????? ???????? ???????
- @@ForI:
- ;????? ??????????? ????? ????????
- mov ah, 09h
- lea dx, PromptA1
- int 21h
- mov ax, si
- call Show_AX
- mov ah, 09h
- lea dx, PromptA2
- int 21h
- ;???? ?????
- mov ah, 0Ah ;???? ??????
- mov dx, offset kbdBuffer
- int 21h
- mov ah,09h ;??????? ?????? (?? ????? ??????)
- lea dx, CrLf
- int 21h
- push si
- lea si, kbdBuffer+1 ; ?????????????? ?????? ? ?????
- call Str2Num
- pop si
- ; ???????? ?? ??????
- jnc @@NoError
- ; ???? ???? ?????? ????? - ????????? ????
- jmp @@ForI
- ; ???? ??? ?????? ????? - ????????? ?????
- @@NoError:
- ;?????????? ?????????? ?????? ? ???????
- ;mov [di], ax
- ;??????? ? ?????????? ????????
- inc si
- add di, 2
- loop @@ForI
- @@Exit:
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- InputArray endp
- ends
- end begin ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement