Batisk_AFF

Lab2

Feb 14th, 2021
238
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Template for console application
  2.          .586
  3.          .MODEL  flat, stdcall
  4.          OPTION CASEMAP:NONE
  5.  
  6. Include kernel32.inc
  7. Include masm32.inc
  8.  
  9. IncludeLib kernel32.lib
  10. IncludeLib masm32.lib
  11.  
  12.          .CONST
  13. MsgExit  DB 13, 10, "Press Enter to Exit", 0;, 13, 10, 0;,0AH,0DH,0
  14. str_err  DB "Error, enter another q!", 13, 10, 0
  15.  
  16.          .DATA
  17. ;s sbyte ?
  18. ;a sbyte 10
  19. ;q sbyte 5
  20. str_task DB "s = q^3 - 2*a*q + (a^2)/q", 13, 10, 0
  21. str_in_q DB 13, 10, "Input q: ", 0
  22. str_in_a DB 13, 10, "Input a: ", 0
  23. str_res  DB 13, 10, "Result: ", 0
  24. resstr DB 16 DUP (?)        
  25.  
  26.          .DATA?
  27. s sword ?
  28. a sword ?
  29. q sword ?        
  30. inbuf  DB 100 DUP (?)
  31. buffer DB 10 DUP (?)
  32.  
  33.          .CODE
  34. Start:
  35.  
  36. ; values input
  37. Invoke StdOut, ADDR str_task ; task output
  38.  
  39. Invoke StdOut, ADDR str_in_a ; a input text
  40. Invoke StdIn, ADDR buffer, LengthOf buffer ; a input
  41. Invoke StripLF, ADDR buffer  ; "1337\n" -> "13370"
  42. Invoke atol, ADDR buffer     ; "13770" -> 1337
  43. mov DWORD PTR a, EAX
  44.  
  45. Invoke StdOut, ADDR str_in_q ; q input text
  46. Invoke StdIn, ADDR buffer, LengthOf buffer ; q input
  47. Invoke StripLF, ADDR buffer  ; "1337\n" -> "13370"
  48. Invoke atol, ADDR buffer     ; "13770" -> 1337
  49. mov DWORD PTR q, EAX
  50.  
  51.  
  52. compare:
  53.     cmp q, 0
  54.     je error
  55.     jmp continue
  56.  
  57. error:
  58.     Invoke StdOut, ADDR str_err  ; error text
  59.     Invoke StdOut, ADDR str_in_q ; q input text
  60.     Invoke StdIn, ADDR buffer, LengthOf buffer ; q input
  61.     Invoke StripLF, ADDR buffer ; "1337\n" -> "13370"
  62.     Invoke atol, ADDR buffer     ; "13770" -> 1337
  63.     mov DWORD PTR q, EAX
  64.     jmp compare
  65.  
  66. continue:
  67.     ;XOR EAX, EAX ; clear EAX
  68.    
  69.     ; q^3
  70.     mov AX, q
  71.     mul q
  72.     ;mov s, AL ; debug mov
  73.     mul q
  74.     mov s, AX
  75.    
  76.     ; -2*a*q
  77.     mov AX, 2
  78.     mul a
  79.     mul q
  80.     sub s, AX
  81.    
  82.     ; + (a^2)/q
  83.     mov AX, a
  84.     mul a
  85.     div q
  86.     add s, AX
  87.    
  88.     ; for a=10 & q=5 :   s=2D (hex) or 45 (dec)
  89.  
  90.     Invoke dwtoa,s,ADDR resstr ; result number to string
  91.     Invoke StdOut, ADDR str_res ; result text
  92.     Invoke StdOut,ADDR resstr  ; result output
  93.  
  94.     XOR EAX, EAX                            ; clear EAX
  95.     Invoke StdOut,ADDR MsgExit              ; exit message output
  96.     Invoke StdIn,ADDR inbuf,LengthOf inbuf  ; waiting for enter to close
  97.    
  98.     Invoke ExitProcess,0
  99.     End    Start
  100.  
  101.  
RAW Paste Data