Advertisement
Guest User

rares

a guest
Jan 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. bits 32 ; assembling for the 32 bits architecture
  2.  
  3. ; declare the EntryPoint (a label defining the very first instruction of the program)
  4. global start
  5.  
  6. ; declare external functions needed by our program
  7. extern exit,scanf,printf ; tell nasm that exit exists even if we won't be defining it
  8. import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
  9. import scanf msvcrt.dll ; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
  10. import printf msvcrt.dll
  11. ; our data is declared here (the variables needed by our program)
  12. segment data use32 class=data
  13. a dd 0
  14. b dd 0
  15. nr dd 0
  16. format_citire db "%u %u %u",0
  17. format_afisare db "%u",10,0
  18. ; our code starts here
  19. segment code use32 class=code
  20.  
  21. interval:
  22. ;functie ce determina daca un nr apartine unui interval inchis (interpretare fara semn)
  23. ;input: nr, a, b - dword
  24. ;output: -
  25. ;post: eax 0 nu; eax 1 da
  26. mov eax, 1
  27. mov ebx, [esp+4];nr
  28. mov ecx, [esp+8];a
  29. mov edx, [esp+12];b
  30.  
  31. cmp ebx,ecx
  32. jb .nu_e
  33.  
  34. cmp ebx,edx
  35. ja .nu_e
  36.  
  37. ret
  38.  
  39. .nu_e:
  40.  
  41. mov eax, 0
  42. ret
  43.  
  44.  
  45. start:
  46.  
  47. .bucla:
  48. push dword b
  49. push dword a
  50. push dword nr
  51. push dword format_citire
  52. call [scanf]
  53. add esp,4*4
  54.  
  55. cmp dword [nr],0
  56. je .gata
  57.  
  58. push dword [b]
  59. push dword [a]
  60. push dword [nr]
  61. call interval
  62. add esp,4*3
  63.  
  64. push eax
  65. push dword format_afisare
  66. call [printf]
  67. add esp, 4*2
  68.  
  69.  
  70. jmp .bucla
  71.  
  72. .gata:
  73. push dword 0 ; push the parameter for exit onto the stack
  74. call [exit] ; call exit to terminate the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement