Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. lg0; decomment according to platform (Linux or Windows)
  2. ;%include "include/io.lin.inc"
  3. %include "include/io.win.inc"
  4.  
  5. section .text
  6. dd lg0 0
  7. dd lg1 0
  8. global do_operation
  9.  
  10. ; TODO dissasemble the main.o file. Be sure not to overwrite registers used
  11. ; by main.o that he does not save himself.
  12. ; If you see your program going nuts, consider looking in the main.o disassembly
  13. ; for the causes mentioned earlier.
  14.  
  15. do_operation:
  16.  
  17. xor eax,eax
  18. xor ecx,ecx
  19. xor edx,edx
  20. xor ebx,ebx
  21.  
  22. mov eax,[ebp+8] ;pointer care primu numar
  23. mov ebx,[ebp+12] ;pointer care al doilea numea
  24.  
  25. mov ecx,[eax+4] ;lungimea primului nr
  26. mov edx,[ebx+4];lungimea numarului al doilea
  27.  
  28. mov [lg0],ecx ;lg0 contine lungimea pentru primul nr
  29. mov [lg1],edx ;lg1 contine lg pentru al doilea nr
  30.  
  31. mov ebx,[ebp+16] ; verific operatia
  32. cmp ebx,'|'
  33. jmp or_biti
  34. cmp ebx,'&'
  35. jmp and_biti
  36.  
  37.  
  38. or_biti: ;calculez sau pe biti pentru fiecare byte din numar
  39. mov ecx,[lg0]
  40. mov edx,[lg1]
  41.  
  42. mov eax,[ebp+8]
  43. mov ebx,[ebp+12]
  44.  
  45. cmp ecx,edx ;daca lungimea cea mai mica este a primului numar,o sa fac loop un loop care se termina cand lungimea acestuia se termina
  46. jl continuare
  47. continuare:
  48. mov ebx,[eax+8+ecx]
  49. mov ecx,ebx
  50. mov ebx,[ebp+12]
  51. mov eax,[ebx+8+edx]
  52. mov ebx,eax
  53.  
  54. or ecx,ebx ; fac sau in bytes numarului
  55.  
  56. mov edx,[lg0]
  57. mov eax,[ebp+8]
  58. mov [eax+8+edx],ecx ;pun informatia in memoria,in locul informatiei numarului de la ebp+8
  59.  
  60. mov ecx,[lg0]
  61. dec ecx
  62. mov [lg0],ecx
  63.  
  64. mov ebx,[lg1]
  65. dec ebx
  66. mov [lg1],ebx ;decrementez lungimile ambelor numere
  67.  
  68. cmp ecx,0
  69. jne or_biti
  70. cmp ecx,0
  71. je final
  72.  
  73.  
  74. cmp ecx,edx ;daca lungimea celui de al doilea este mai mare,fac un loop care se termina cand lungimea acestuia se termina
  75. jge continuare2: ;proces identic cu cel de mai sus,difera doar momentul de oprire al loopului
  76. mov ebx,[eax+8+ecx]
  77. mov ecx,ebx
  78. mov ebx,[ebp+12]
  79. mov eax,[ebx+8+edx]
  80. mov ebx,eax
  81.  
  82. or ecx,ebx
  83.  
  84. mov edx,[lg0]
  85. mov eax,[ebp+8]
  86. mov [eax+8+edx],ecx
  87.  
  88. mov ecx,[lg0]
  89. dec ecx
  90. mov [lg0],ecx
  91.  
  92. mov ebx,[lg1]
  93. dec ebx
  94. mov [lg1],ebx
  95.  
  96. cmp ebx,0
  97. jne or_biti
  98. cmp ebx,0
  99. je final
  100.  
  101. jmp or_biti
  102.  
  103.  
  104. and_biti: ;intregul proces este identic cu or_biti,difera doar operatie de and in loc de or
  105.  
  106. mov ecx,[lg0]
  107. mov edx,[lg1]
  108.  
  109. mov eax,[ebp+8]
  110. mov ebx,[ebp+12]
  111.  
  112. cmp ecx,edx
  113. jl continuare_si
  114. continuare_si:
  115. mov ebx,[eax+8+ecx]
  116. mov ecx,ebx
  117. mov ebx,[ebp+12]
  118. mov eax,[ebx+8+edx]
  119. mov ebx,eax
  120.  
  121. or ecx,ebx
  122.  
  123. mov edx,[lg0]
  124. mov eax,[ebp+8]
  125. mov [eax+8+edx],ecx
  126.  
  127. mov ecx,[lg0]
  128. dec ecx
  129. mov [lg0],ecx
  130.  
  131. mov ebx,[lg1]
  132. dec ebx
  133. mov [lg1],ebx
  134.  
  135. cmp ecx,0
  136. jne and_biti
  137. cmp ecx,0
  138. je final
  139.  
  140. cmp ecx,edx
  141. jge continuare2_si:
  142. mov ebx,[eax+8+ecx]
  143. mov ecx,ebx
  144. mov ebx,[ebp+12]
  145. mov eax,[ebx+8+edx]
  146. mov ebx,eax
  147.  
  148. or ecx,ebx
  149.  
  150. mov edx,[lg0]
  151. mov eax,[ebp+8]
  152. mov [eax+8+edx],ecx
  153.  
  154. mov ecx,[lg0]
  155. dec ecx
  156. mov [lg0],ecx
  157.  
  158. mov ebx,[lg1]
  159. dec ebx
  160. mov [lg1],ebx
  161.  
  162. cmp ebx,0
  163. jne and_biti
  164. cmp ebx,0
  165. je final
  166.  
  167. jmp and_biti
  168.  
  169.  
  170.  
  171. final:
  172. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement