Advertisement
Guest User

Lab6p15

a guest
Nov 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 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, 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 printf msvcrt.dll ; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
  10.  
  11. ; our data is declared here (the variables needed by our program)
  12. segment data use32 class=data
  13. ; ...Se da un sir de octeti S. Sa se construiasca sirul D ale carui elemente reprezinta suma fiecaror doi octeti consecutivi din sirul S.
  14.  
  15. sursa db 1,2,3,4,5,6
  16. ls equ ($-sursa)
  17. dest TIMES ls db 0
  18. format db "Sirul este: ",0
  19. format2 db "%d ",0
  20. ; our code starts here
  21. segment code use32 class=code
  22. start:
  23. ; ...
  24. mov esi,0
  25. mov al,[sursa+esi]
  26. mov edi,0
  27. inc esi
  28. for_sir:
  29. cmp esi,ls
  30. je end_for
  31. mov bl,[sursa+esi]
  32. add al,bl
  33. mov [dest+edi],al
  34. inc edi
  35. inc esi
  36. mov al,bl
  37. jmp for_sir
  38.  
  39. end_for:
  40. push dword format
  41. call[printf]
  42. add esp, 4*1
  43. mov esi,0
  44.  
  45.  
  46. repeta:
  47. cmp esi,ls-1
  48. je final
  49. pushad
  50. mov al,[dest+esi]
  51. cbw
  52. cwde
  53. push eax
  54. push dword format2
  55. call [printf]
  56. add esp, 4*2
  57. popad
  58. add esi,1
  59. jmp repeta
  60.  
  61.  
  62. final:
  63. ; exit(0)
  64. push dword 0 ; push the parameter for exit onto the stack
  65. call [exit] ; call exit to terminate the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement