Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. model small
  2. .386
  3. .stack 100h
  4. .data
  5. str1 db 'Input two numbers:',0Dh,0Ah,'$'
  6. str2 db 'Wrong Number. Please input correct number:',0Dh,0Ah,'$'
  7. max db 10
  8. len db 0
  9. buffer db 11 dup(0)
  10. ten dw 10
  11. digit dw 0
  12. x dq 0
  13. x1 dq 0
  14. x2 dq 0
  15. delta_x dq 0
  16. max_y dq -999.9
  17. min_y dq 999.9
  18. screen_height dw 480
  19. screen_width dw 639
  20. func_arr dq 640 dup(0)
  21. func_arr_scale dw 640 dup(0)
  22. .code
  23. start:
  24.     mov ax,@data
  25.     mov ds,ax
  26.     mov ah,09h
  27.     lea dx,str1
  28.     int 21h
  29.     finit
  30. input:
  31.     lea di,x1
  32.     call input_number
  33.     cmp al,01h
  34.     je re_input
  35.     mov ah,0Eh
  36.     mov al,0Ah
  37.     int 10h
  38.     mov ah,0Eh
  39.     mov al,0Dh
  40.     int 10h
  41.     lea di,x2
  42.     call input_number
  43.     cmp al,01h
  44.     je re_input
  45.     fld x1
  46.     fld x2
  47.     fcom st(1)
  48.     fstsw ax
  49.     fwait
  50.     sahf
  51.     jbe re_input
  52.     fstp x2
  53.     fstp x1
  54. draw:
  55.     fld x2
  56.     fld x1
  57.     fsubp st(1),st(0)
  58.     fild screen_width
  59.     fdivp st(1),st(0)
  60.     fstp delta_x
  61.     fld x1
  62.     fstp x
  63.     mov cx,screen_width
  64.     xor di,di
  65. calc_step:
  66.     call func
  67.     fld x
  68.     fld delta_x
  69.     faddp st(1),st(0)
  70.     fstp x
  71.     loop calc_step
  72. scale:
  73.     fild screen_height
  74.     fld max_y
  75.     fld min_y
  76.     fsubp st(1),st(0)
  77.     fdivp st(1),st(0)
  78.     xor si,si
  79.     mov cx,640
  80.     xor di,di
  81. loop_scale:
  82.     fld max_y
  83.     fld func_arr[si]
  84.     fsubp st(1),st(0)
  85.     fmul st(0),st(1)
  86.     fistp func_arr_scale[di]
  87.     add di,02h
  88.     add si,08h
  89.     loop loop_scale
  90.     fstp min_y
  91. drawing:
  92.     mov ah,00h
  93.     mov al,12h
  94.     int 10h
  95.     mov si,1278
  96.     mov cx,640
  97.     xor bh,bh
  98. draw_loop:
  99.     push cx
  100.     dec cx
  101.     mov ah,0Ch
  102.     mov al,15
  103.     mov dx,func_arr_scale[si]
  104.     int 10h
  105.     sub si,2
  106.     pop cx
  107.     loop draw_loop
  108.     mov ah,00h
  109.     int 16h
  110.     mov ax,4C00h
  111.     int 21h
  112. re_input:
  113.     mov ax,03h
  114.     int 10h
  115.     mov ah,09h
  116.     lea dx,str2
  117.     int 21h
  118.     jmp input
  119. func proc
  120.     fld x
  121.     fcos
  122.     fmul st(0),st(0)
  123.     fmulp st(1),st(0)
  124.     fld x
  125.     fmul st(0),st(0)
  126.     fmul st(0),st(0)
  127.     fld x
  128.     fsin
  129.     fmul st(0),st(0)
  130.     fmul st(0),st(0)
  131.     fmulp st(1),st(0)
  132.     faddp st(1),st(0)
  133. comp_max:
  134.     fcom max_y
  135.     fstsw ax
  136.     fwait
  137.     sahf
  138.     ja bigger
  139. comp_min:
  140.     fcom min_y
  141.     fstsw ax
  142.     fwait
  143.     sahf
  144.     jb smaller
  145.     jmp end_calc
  146. bigger:
  147.     fst max_y
  148.     jmp comp_min
  149. smaller:
  150.     fst min_y
  151. end_calc:
  152.     fstp func_arr[di]
  153.     add di,08h
  154. ret
  155. func endp
  156. input_number proc
  157.     mov ah,0Ah
  158.     lea dx,max
  159.     int 21h
  160.     xor ax,ax
  161.     xor bx,bx
  162.     xor cx,cx
  163.     xor si,si
  164.     xor dx,dx
  165.     fldz
  166.     mov al,buffer[si]
  167.     inc si
  168.     cmp al,'-'
  169.     jne plus
  170.     mov dh,01h
  171.     jmp number
  172. plus:
  173.     cmp al,'+'
  174.     jne dot
  175.     jmp number
  176. dot:
  177.     cmp al,'.'
  178.     jne digits
  179.     mov dl,01h
  180. next_is_digit:
  181.     mov al,buffer[si]
  182.     inc si
  183. start_parse:
  184.     dec si
  185. number:
  186.     xor ax,ax
  187.     mov al,len
  188.     cmp si,ax
  189.     je fraction
  190.     mov al,buffer[si]
  191.     inc si
  192.     cmp al,'.'
  193.     jne digits
  194.     cmp dl,01h
  195.     je error_input
  196.     mov dl,01h
  197.     jmp next_is_digit
  198. digits:
  199.     cmp al,'0'
  200.     jb error_input
  201.     cmp al,'9'
  202.     ja error_input
  203.     inc bx
  204.     fild ten
  205.     fmulp st(1)
  206.     sub al,'0'
  207.     mov digit,ax
  208.     fiadd digit
  209.     cmp dl,00h
  210.     je number
  211.     inc cx
  212.     jmp number
  213. fraction:
  214.     cmp cx,00h
  215.     je final
  216.     fild ten
  217.     fdivp st(1),st(0)
  218.     loop fraction
  219. final:
  220.     cmp bx,00h
  221.     je error_input
  222.     cmp dh,01h
  223.     jne is_over
  224.     fchs
  225. is_over:
  226.     mov al,00h
  227. store:
  228.     fstp qword ptr [di]
  229. ret
  230. error_input:
  231.     mov al,01h
  232.     jmp store
  233. ret
  234. input_number endp
  235. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement