Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: ASM (NASM)  |  size: 5.32 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. code_segment segment para public "code"
  2. org 100h
  3.  
  4. complex struc
  5.         Re      dw      ?
  6.         Im      dw      ?
  7. complex ends
  8.  
  9. i_1 complex<>
  10. i_2 complex<>
  11.  
  12. EnterFailureMessage             db                      "Ошибка ввода$"
  13. i_1_Re_Message                          db                      "Введите целое число 1: $"
  14. i_1_Im_Message                          db                      "Введите комплексную часть числа 1: $"
  15. i_2_Re_Message                          db                      "Введите целое число 2: $"
  16. i_2_Im_Message                          db                      "Введите комплексную часть числа 2: $"
  17. AddOperation                            db                      "Сложение: $"
  18. SubOperation                            db                      "Вычитание: $"
  19. MulOperation                            db                      "Умножение: $"
  20. DivOperation                            db                      "Деление: $"
  21.  
  22. buffer                                          db                      6,7 dup( ? )
  23.  
  24. assume                                          ds:code_segment,ss:code_segment,cs:code_segment
  25.  
  26. waiting proc
  27.         mov             ah,             01h
  28.         int             21h
  29.         ret
  30. waiting endp
  31.  
  32. gonextline proc
  33.         mov             dx,     0Ah
  34.         call            print_symbol
  35.         int             21h
  36.         ret
  37. gonextline endp
  38.  
  39. value_input proc
  40.         xor             di,                             di
  41.         mov             ah,                     0Ah
  42.         mov             dx,                     offset buffer
  43.         int             21h
  44.         call            gonextline
  45.        
  46.         mov             si,                             offset buffer + 2
  47.         cmp             byte ptr [si],  '-'
  48.         jne             value_position
  49.         mov             di,                     1
  50.         inc             si
  51.        
  52.         value_position:
  53.         xor             ax,                              ax
  54.         mov             bx,                              0Ah
  55.        
  56.         check_cycle:
  57.         mov             cl,                     [si]
  58.         cmp             cl,                     0Dh
  59.         je                      check_end
  60.        
  61.         cmp             cl,                             30h
  62.         jl                      input_error_mark
  63.         cmp             cl,                     39h
  64.         ja                      input_error_mark
  65.        
  66.         sub             cl,                             30h
  67.         mul             bx
  68.         add             ax,                             cx
  69.         inc             si
  70.         jmp             check_cycle
  71.        
  72.         input_error_mark:
  73.         lea             dx,                             EnterFailureMessage
  74.         call            print_string
  75.         call            gonextline
  76.         jmp             value_input
  77.        
  78.         check_end:
  79.         cmp             di,                             1
  80.         jne             input_proc_end
  81.         neg             ax
  82.        
  83.         input_proc_end:
  84.         ret
  85.  
  86. value_input endp
  87.  
  88. int_to_string proc
  89.         xor             cx,                             cx
  90.         xor             di,                             di
  91.         sub             bx,                             0
  92.  
  93.         jns                     not_negative_value
  94.         js                      negative_value
  95.        
  96.         negative_value:
  97.         mov             dx,                             '-'
  98.         call            print_symbol
  99.         neg             bx
  100.         mov             di,                             1
  101.         jmp                     continue_parse
  102.        
  103.         not_negative_value:
  104.         mov             dx,                             '+'
  105.         call            print_symbol
  106.         mov             di,                             0
  107.         jmp                     continue_parse
  108.        
  109.         continue_parse:
  110.         mov             ax,                             bx
  111.         mov             dx,                             0Ah
  112.         idiv            dl
  113.         add             ah,                             30h
  114.         mov             dl,                             ah
  115.         push            dx
  116.         xor             bx,                             bx
  117.         mov             bl,                             al
  118.         inc             cx
  119.         cmp             bx,                             0
  120.         jz                      end_of_translation
  121.         jmp             continue_parse
  122.         end_of_translation:
  123.         pop             dx
  124.         call            print_symbol
  125.         loop end_of_translation
  126.  
  127.         ret
  128. int_to_string endp
  129.  
  130. print_symbol proc
  131.         xor             ax,                             ax
  132.         mov                     ah,                     02h
  133.         int                     21h
  134.         ret
  135. print_symbol endp
  136.  
  137. print_string proc
  138.         mov                     ah,                             09h
  139.         int                     21h
  140.         ret
  141. print_string endp
  142.  
  143. end_program proc
  144.         mov             ax,                             4c00h
  145.         int             21h
  146.         ret
  147. end_program endp
  148.  
  149.         ;---------------------------------
  150.         ;       Main procedure
  151.         ;---------------------------------
  152.  
  153. main proc
  154.         mov             ax,                             code_segment
  155.         mov             ds,                             ax
  156.        
  157.         lea                     dx,                             i_1_Re_Message
  158.         call            print_string
  159.         call            value_input
  160.         mov             word ptr i_1.Re,ax
  161.        
  162.         lea                     dx,                             i_1_Im_Message
  163.         call            print_string
  164.         call            value_input
  165.         mov             word ptr i_1.Im,ax
  166.        
  167.         lea                     dx,     i_2_Re_Message
  168.         call            print_string
  169.         call            value_input
  170.         mov             word ptr i_2.Re,ax
  171.        
  172.         lea                     dx,     i_2_Im_Message
  173.         call            print_string
  174.         call            value_input
  175.         mov             word ptr i_2.Im,ax
  176.        
  177.        
  178.         ;---------------------------------
  179.         ;       Addition
  180.         ;---------------------------------
  181.         lea                     dx,                             AddOperation
  182.         call            print_string
  183.        
  184.         mov             ax,                             i_1.Re
  185.         add             ax,                             i_2.Re
  186.        
  187.         mov             bx,                             ax
  188.         call            int_to_string
  189.        
  190.         mov             ax,                             i_1.Im
  191.         add             ax,                             i_2.Im
  192.        
  193.         mov             bx,                             ax
  194.         call            int_to_string
  195.        
  196.         mov             dx,                             'i'
  197.         call            print_symbol
  198.         call            gonextline
  199.        
  200.         ;---------------------------------
  201.         ;       Subtraction
  202.         ;---------------------------------
  203.         lea                     dx,                             SubOperation
  204.         call            print_string
  205.        
  206.         mov             ax,                             i_1.Re
  207.         sub             ax,                             i_2.Re
  208.        
  209.         mov             bx,                             ax
  210.         call            int_to_string
  211.        
  212.         mov             ax,                             i_1.Im
  213.         sub             ax,                             i_2.Im
  214.        
  215.         mov             bx,                             ax
  216.         call            int_to_string
  217.        
  218.         mov             dx,'i'
  219.         call            print_symbol
  220.         call            gonextline
  221.        
  222.         ;---------------------------------
  223.         ;       Multiplication
  224.         ;---------------------------------
  225.         lea                     dx,                             MulOperation
  226.         call            print_string
  227.        
  228.         mov             ax,                             i_1.Re
  229.         imul            i_2.Re
  230.        
  231.         mov             bx,                             ax
  232.        
  233.         mov             ax,                             i_1.Im
  234.         imul            i_2.Im
  235.         neg             ax
  236.         add             bx,                             ax
  237.         call            int_to_string
  238.        
  239.         mov             ax,                             i_1.Re
  240.         imul            i_2.Im
  241.         mov             bx,                             ax
  242.        
  243.         mov             ax,                             i_1.Im
  244.         imul            i_2.Re
  245.         add             bx,                             ax
  246.         call            int_to_string
  247.         mov                     dx,                             'i'
  248.         call            print_symbol
  249.        
  250.         call            gonextline
  251.        
  252.         ;---------------------------------
  253.         ;       Division
  254.         ;---------------------------------
  255.         lea                     dx,                             DivOperation
  256.         call            print_string
  257.        
  258.         mov             dx,                             '('
  259.         call            print_symbol
  260.         mov             ax,                             i_1.Re
  261.         imul            i_2.Re
  262.         mov             bx,                             ax
  263.        
  264.         mov             ax,                             i_1.Im
  265.         imul            i_2.Im
  266.         add             bx,                             ax
  267.         call            int_to_string
  268.        
  269.        
  270.         mov             ax,                             i_1.Re
  271.         imul            i_2.Im
  272.         neg             ax
  273.         mov             bx,                             ax
  274.        
  275.         mov             ax,                             i_1.Im
  276.         imul            i_2.Re
  277.         add             bx,                             ax
  278.         call            int_to_string
  279.         mov             dx,                             'i'
  280.         call            print_symbol
  281.        
  282.         mov             dx,                             ')'
  283.         call            print_symbol
  284.        
  285.         mov             dx,                             '/'
  286.         call            print_symbol
  287.        
  288.        
  289.         mov             ax,                             i_2.Re
  290.         imul            i_2.Re
  291.         mov             bx,                             ax
  292.        
  293.         mov             ax,                             i_2.Im
  294.         imul            i_2.Im
  295.         add             bx,                             ax
  296.         call            int_to_string
  297.        
  298.        
  299.         ;------------------------------------------
  300.         ;       End of program
  301.         ;------------------------------------------
  302.         call            waiting
  303.         call            end_program
  304. main endp
  305. code_segment ends
  306. end main