Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .stack 100h
  3.  
  4. data segment                 ;??????? ??????
  5.     msg_first  db 13,10,'Enter number of elements: $'
  6.     msg_second db 13,10,'Enter number: $'
  7.     msg_plus   db ', $'
  8.     msg_mod  db 13,10,'Result module: $'
  9.     msg_mul    db 13,10,'Result invers: $'
  10.     msg_div    db 13,10,'Result div: $'
  11.     msg_no_div db 13,10,'Cant div$'
  12.     msg_sqr    db 13,10,'Result sqr: $'
  13.     msg_div_al db 13,10,'Whole part: $'
  14.     msg_div_ah db 13,10,'Surplus: $'
  15.    
  16.     n   dw 1 dup(?)
  17.     b   db 10 dup('$')  ;second number
  18.     c  dw 10 dup('$')   ;result
  19.     buff db 10 dup('$')
  20.     buff1 db 10 dup('$')
  21.     d db 10 dup('$')
  22. data ends
  23.  
  24. code segment                 ;??????? ????
  25. assume cs:code,ds:data       ;??????? ??? code, data ?????????? ??? ? ??????
  26.  
  27. start:
  28.     mov ax, 3               ;clear screen
  29.     int 10h
  30.     mov ax, data            ;??? ???? ????? ??????? ?????? ? ds(??????? ??????) ??????? ??????? ? ax
  31.     mov ds, ax
  32.     lea dx, msg_first
  33.     lea bx, buff
  34.     lea cx, n
  35.     CALL _input
  36.     xor si, si  
  37. enter_array:  
  38.     cmp si, n
  39.     je op_preinv
  40.     lea cx, b[si]
  41.     lea dx, msg_second
  42.     lea bx, buff1
  43.     CALL _input
  44.     CALL _fillcharbuff1  
  45.     inc si
  46.     jmp enter_array
  47. op_preinv:
  48.     xor si, si
  49.     lea dx, msg_mul
  50.     mov ah, 9
  51.     int 21h  
  52.     CALL _fillchar
  53. op_inv:                                                              
  54.     cmp si, n
  55.     je op_premod  
  56.     xor ah, ah
  57.     mov al, b[si]
  58.     cmp b[si], 0
  59.     jns posit
  60.     mov ah, 1
  61.     neg ah
  62. posit:
  63.     neg ax
  64.     CALL _fillcharc
  65.     mov c, ax
  66.     CALL _write
  67.     lea dx, msg_plus
  68.     mov ah, 9
  69.     int 21h
  70.     inc si
  71.     jmp op_inv
  72.  
  73. op_premod:
  74.     xor si, si
  75.     lea dx, msg_mod
  76.     mov ah, 9
  77.     int 21h  
  78.     CALL _fillchar
  79. op_mod:
  80.     cmp si, n
  81.     je op_presqr                                          
  82.     xor ah, ah  
  83.     mov al, b[si]
  84.     cmp al, 0
  85.     jns mod_cont
  86.     cmp b[si], 0
  87.     jns posit1
  88.     mov ah, 1
  89.     neg ah
  90. posit1:
  91.     neg ax
  92. mod_cont:
  93.     CALL _fillcharc
  94.     mov c, ax  
  95.     CALL _write  
  96.     lea dx, msg_plus
  97.     mov ah, 9
  98.     int 21h
  99.     inc si
  100.     jmp op_mod
  101.  
  102. op_presqr:
  103.     xor si, si
  104.     lea dx, msg_sqr
  105.     mov ah, 9
  106.     int 21h  
  107.     CALL _fillchar    
  108.    
  109. op_sqr:  
  110.     cmp si, n
  111.     je op_prediv
  112.     mov  al, b[si]
  113.     mov  ah, b[si]
  114.     imul ah  
  115.     CALL _fillcharc
  116.     mov  c, ax  
  117.     CALL _write
  118.     lea dx, msg_plus
  119.     mov ah, 9
  120.     int 21h
  121.     inc si
  122.     jmp op_sqr
  123.  
  124. op_prediv:
  125.     xor si, si
  126.     lea dx, msg_div
  127.     mov ah, 9
  128.     int 21h    
  129. op_div:  
  130.     cmp si, n
  131.     je @@_exit
  132.     mov ax, 1
  133.     mov  bl, b[si]    
  134.     cmp bx, 0
  135.     je  op_no_div
  136.     idiv bl    
  137.     CALL _fillcharc
  138.     push ax
  139.     lea dx, msg_div_al
  140.     mov ah, 9
  141.     int 21h
  142.     pop ax
  143.     push ax  
  144.     mov ah, 0
  145.     cmp b[si], 0
  146.     jns op_div_cont
  147.     mov ah, 1
  148.     neg ah
  149. op_div_cont:
  150.     mov  c, ax
  151.     CALL _fillchar  
  152.     CALL _write
  153.     lea dx, msg_div_ah
  154.     mov ah, 9
  155.     int 21h  
  156.     pop ax
  157.     mov al, ah
  158.     mov ah, 0
  159.     mov  c, ax  
  160.     CALL _fillchar
  161.     CALL _write
  162.     lea dx, msg_plus
  163.     mov ah, 9
  164.     int 21h
  165.     inc si
  166.     jmp op_div
  167. op_no_div:    
  168.      lea dx, msg_no_div
  169.      mov ah, 9
  170.      int 21h
  171.      inc si
  172.      jmp op_div
  173.      
  174. @@_exit:
  175.     int 20h
  176.    
  177. _input proc    
  178.     push si
  179.     push cx
  180.     xor di,di
  181.     mov ah, 9
  182.     int 21h
  183.  
  184.     mov dx,bx
  185.     mov ah, 0ah
  186.     int 21h
  187.     mov si, dx
  188.     add bl, [si+1]     
  189.     add bx, 2            
  190.     mov [bx],'$'
  191.    
  192.     add si, 2
  193.     cmp byte ptr [si], "-"
  194.     jnz ii1
  195.     mov di,1
  196.     inc si
  197. ii1:
  198.     xor ax,ax
  199.     mov bx,10  ;
  200. ii2:
  201.     mov cl,[si]
  202.     cmp cl,'$'  
  203.     jz endin
  204.    
  205.  
  206.     cmp cl,'0'  
  207.     jl er
  208.     cmp cl,'9'  
  209.     ja er
  210.  
  211.     sub cl,'0'
  212.     mul bx    
  213.     add ax,cx  
  214.     inc si    
  215.     jmp ii2    
  216.  
  217. er:  
  218.     int 20h
  219.  
  220.  
  221. endin:
  222.     cmp di,1
  223.     jnz ii3
  224.     neg ax  
  225. ii3:
  226.     pop cx    
  227.     mov si,cx
  228.     mov [si], ax
  229.     pop si
  230.     ret
  231. _input endp
  232.  
  233. _write proc
  234.     push si
  235.     push bx
  236.     lea si,d
  237.     mov bx,10
  238.     xor cx,cx  
  239.     lea di,c
  240.     cmp [di], -1    
  241.     jg @@asc2
  242.     mov [si], '-'
  243.     inc si
  244.     neg ax
  245. @@asc2:
  246.     xor dx,dx
  247.     div bx
  248.     add dx,48  
  249.     push dx  
  250.     inc cx
  251.     cmp ax,0
  252.     jz @@rever
  253.     jmp @@asc2      
  254. @@rever:
  255.     pop dx
  256.     mov [si], dl  
  257.     inc si  
  258.     dec cx    
  259.     cmp cx, 0
  260.     jz @@end
  261.     jmp @@rever
  262. @@end:
  263.     mov ah, 9
  264.     lea dx, d
  265.     int 21h
  266.     pop bx
  267.     pop si
  268. ret
  269. _write endp
  270.  
  271. _fillchar proc
  272.     push si
  273.     xor si, si
  274. fcl1:
  275.     cmp si, 10
  276.     je fclend
  277.     mov d[si], '$'
  278.     inc si
  279.     jmp fcl1
  280. fclend:
  281.     pop si  
  282.     ret
  283. _fillchar endp
  284.  
  285. _fillcharc proc
  286.     push si
  287.     xor si, si
  288. fclc1:
  289.     cmp si, 10
  290.     je fclend
  291.     mov c[si], '$'
  292.     inc si
  293.     jmp fcl1
  294. fclcend:
  295.     pop si  
  296.     ret
  297. _fillcharc endp
  298.  
  299. _fillcharbuff1 proc
  300.     push si
  301.     xor si, si
  302. fclb1:
  303.     cmp si, 10
  304.     je fclbend
  305.     mov buff1[si], '$'
  306.     inc si
  307.     jmp fclb1
  308. fclbend:
  309.     pop si  
  310.     ret
  311. _fillcharbuff1 endp
  312.  
  313. end start
  314. code ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement