Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; multi-segment executable file template.
  2.  
  3. data segment
  4.     ; add your data here!
  5.     PromtInfo       db      "Enter the number of elements in array $"
  6.     PromtInfo2      db      "Invers array = $"
  7.     PromtInfo3      db      "Summ = $"
  8.     PromptN         db      'N=', '$'
  9.     PromptA1        db      'A[', '$'
  10.     PromptA2        db      ']=', '$'
  11.     kbdBuffer       db      6, 0, 6 dup(0)
  12.     CrLf            db      0Dh, 0Ah, '$'
  13.  
  14.     N               dw      ?       ;?????? ???????
  15.     A               dw      10 dup (0)
  16.     inversA         dw      10 dup (0)
  17. ends
  18.  
  19.  
  20. code segment
  21.     assume cs:code,ds:data
  22. begin:
  23. ; set segment registers:
  24.     mov ax, data
  25.     mov ds, ax
  26.    
  27.     lea dx, PromtInfo
  28.     mov ah, 9
  29.     int 21h
  30.    
  31.     mov ah, 09h
  32.     lea dx, CrLf
  33.     int 21h
  34. ;-----------------------------------------
  35. Input_N:
  36.     mov ah,09h
  37.     lea dx, PromptN
  38.     int 21h
  39.     mov ah, 0Ah
  40.     lea dx, kbdBuffer
  41.     int 21h
  42.     mov ah, 09h
  43.     lea dx, CrLf
  44.     int 21h
  45.     lea si, kbdBuffer+1
  46.     lea di, N
  47.     call Str2Num
  48. ;---------------------------------------------
  49.     ;???? ???????
  50. Input_Arr:
  51.     mov     cx,     N
  52.     lea     dx,     A
  53.     call    InputArray
  54.    
  55.  
  56. ;--------------------------------
  57.     lea dx, PromtInfo2
  58.     mov ah, 9
  59.     int 21h
  60.    
  61.     mov cx , N
  62.     lea si , A  
  63.     mov bx , 0
  64.     add si, cx
  65.     add si, cx
  66. OutPutArr:
  67.     sub si, 2
  68.     mov ax, [si]
  69.     add bx , ax
  70.     call Show_AX
  71.     mov ah, 02h
  72.     mov dl, ' '
  73.     int 21h
  74.     loop OutPutArr
  75.    
  76.     mov  ah,09h  ;??????? ?????? (?? ????? ??????)
  77.     lea  dx, CrLf
  78.     int  21h
  79.  
  80.     lea dx, PromtInfo3
  81.     mov ah, 9
  82.     int 21h          
  83.                
  84.     mov ax,bx
  85.     call Show_AX
  86.            
  87.     ;lea dx, pkey
  88.     ;mov ah, 9
  89.     ;int 21h        ; output string at ds:dx
  90.    
  91.     ; wait for any key....    
  92.     mov ah, 1
  93.     int 21h
  94.    
  95.     mov ax, 4c00h ; exit to operating system.
  96.     int 21h
  97.    
  98. Str2Num proc
  99.         push    ax
  100.         push    bx
  101.         push    cx
  102.         push    dx
  103.         push    ds
  104.         push    es
  105.         push    si
  106.  
  107.         push    ds
  108.         pop     es
  109.  
  110.         mov     cl, ds:[si]
  111.         xor     ch, ch
  112.  
  113.         inc     si
  114.  
  115.         cmp     [si], byte ptr '-'
  116.         jne     @@IsPositive
  117.         inc     si
  118.         dec     cx
  119. @@IsPositive:
  120.         jcxz    @@Error
  121.  
  122.         mov     bx, 10
  123.         xor     ax, ax
  124.  
  125. @@Loop:
  126.         mul     bx         ; ???????? ax ?? 10 ( dx:ax=ax*bx )
  127.         mov     [di], ax   ; ?????????? ??????? ?????
  128.         cmp     dx, 0      ; ?????????, ????????? ?? ????????????
  129.         jnz     @@Error
  130.  
  131.         mov     al, [si]   ; ??????????? ????????? ?????? ? ?????
  132.         cmp     al, '0'
  133.         jb      @@Error
  134.         cmp     al, '9'
  135.         ja      @@Error
  136.         sub     al, '0'
  137.         xor     ah, ah
  138.         add     ax, [di]
  139.         jc      @@Error    ; ???? ????? ?????? 65535
  140.         inc     si
  141.  
  142.         loop    @@Loop
  143.  
  144.         pop     si
  145.         push    si
  146.         or      ax, ax
  147.         js      @@Error
  148.         cmp     [si+1], byte ptr '-'
  149.         jne     @@Positive
  150.         neg     ax
  151.         or      ax, ax
  152.         jns     @@Error
  153. @@Positive:
  154.         mov     [di], ax
  155.         clc
  156.         pop     si
  157.         pop     es
  158.         pop     ds
  159.         pop     dx
  160.         pop     cx
  161.         pop     bx
  162.         pop     ax
  163.         ret
  164. @@Error:
  165.         xor     ax, ax
  166.         mov     [di], ax
  167.         stc
  168.         pop     si
  169.         pop     es
  170.         pop     ds
  171.         pop     dx
  172.         pop     cx
  173.         pop     bx
  174.         pop     ax
  175.         ret
  176. Str2Num endp
  177.    
  178.  ; ??????? ????? ?? ???????? AX ?? ?????
  179. ; ??????? ??????:
  180. ; ax - ????? ??? ???????????
  181. Show_AX proc
  182.         push    ax
  183.         push    bx
  184.         push    cx
  185.         push    dx
  186.         push    di
  187.  
  188.         mov     cx, 10          ; cx - ????????? ??????? ?????????
  189.         xor     di, di          ; di - ???. ???? ? ?????
  190.  
  191.         ; ???? ????? ? ax ?????????????, ??
  192.         ;1) ?????????? '-'
  193.         ;2) ??????? ax ?????????????
  194.         or      ax, ax
  195.         jns     @@Conv
  196.         push    ax
  197.         mov     dx, '-'
  198.         mov     ah, 2           ; ah - ??????? ?????? ??????? ?? ?????
  199.         int     21h
  200.         pop     ax
  201.  
  202.         neg     ax
  203.  
  204. @@Conv:
  205.         xor     dx, dx
  206.         div     cx              ; dl = num mod 10
  207.         add     dl, '0'         ; ??????? ? ?????????? ??????
  208.         inc     di
  209.         push    dx              ; ?????????? ? ????
  210.         or      ax, ax
  211.         jnz     @@Conv
  212.         ; ??????? ?? ????? ?? ?????
  213. @@Show:
  214.         pop     dx              ; dl = ????????? ??????
  215.         mov     ah, 2           ; ah - ??????? ?????? ??????? ?? ?????
  216.         int     21h
  217.         dec     di              ; ????????? ???? di<>0
  218.         jnz     @@Show
  219.  
  220.         pop     di
  221.         pop     dx
  222.         pop     cx
  223.         pop     bx
  224.         pop     ax
  225.         ret
  226. Show_AX endp  
  227. ;???? ???????
  228. ;cx - ?????????? ???????? ?????????
  229. ;ds:dx - ????? ???????
  230. InputArray      proc
  231.         push    ax
  232.         push    bx
  233.         push    cx
  234.         push    dx
  235.         push    si
  236.         push    di
  237.  
  238.         jcxz    @@Exit          ;???? ?????? ?????? - ?????????
  239.  
  240.         mov     si,     1       ;?????? ???????? ???????
  241.         mov     di,     dx      ;????? ???????? ???????? ???????
  242.         @@ForI:
  243.                 ;????? ??????????? ????? ????????
  244.                 mov     ah,     09h
  245.                 lea     dx,     PromptA1
  246.                 int     21h
  247.                 mov     ax,     si
  248.                 call    Show_AX
  249.                 mov     ah,     09h
  250.                 lea     dx,     PromptA2
  251.                 int     21h
  252.                 ;???? ?????
  253.                 mov     ah, 0Ah ;???? ??????
  254.                 mov     dx, offset kbdBuffer
  255.                 int     21h
  256.                 mov     ah,09h  ;??????? ?????? (?? ????? ??????)
  257.                 lea     dx, CrLf
  258.                 int     21h
  259.  
  260.                 push    si
  261.                 lea     si, kbdBuffer+1 ; ?????????????? ?????? ? ?????
  262.                 call    Str2Num
  263.                 pop     si
  264.  
  265.                 ; ???????? ?? ??????
  266.                 jnc     @@NoError
  267.  
  268.                 ; ???? ???? ?????? ????? - ????????? ????
  269.                 jmp     @@ForI
  270.  
  271.                 ; ???? ??? ?????? ????? - ????????? ?????
  272.                 @@NoError:
  273.                 ;?????????? ?????????? ?????? ? ???????
  274.                 ;mov    [di],   ax
  275.                 ;??????? ? ?????????? ????????
  276.                 inc     si
  277.                 add     di,     2
  278.         loop @@ForI
  279. @@Exit:
  280.         pop     di
  281.         pop     si
  282.         pop     dx
  283.         pop     cx
  284.         pop     bx
  285.         pop     ax
  286.         ret
  287. InputArray endp
  288.    
  289. ends
  290.  
  291. end begin ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement