Advertisement
Cosmin3105

4

Nov 26th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. .data
  2. matrix: .space 1600
  3. lineIndex: .space 4
  4. columnIndex: .space 4
  5. nr_elem: .space 4
  6. n: .space 4
  7. m: .space 4
  8.  
  9. res: .space 4
  10. op1: .space 4
  11.  
  12. neg1: .long -1
  13.  
  14. sir: .space 400
  15. formatScanf: .asciz "%[^\n]*400"
  16. delim: .asciz " "
  17.  
  18. printnr: .asciz "%d "
  19. newline: .asciz "\n"
  20. .text
  21.  
  22. .global main
  23.  
  24. main:
  25. //scanf("[^\n]*400", &sir)
  26. pushl $sir
  27. pushl $formatScanf
  28. call scanf
  29. popl %ebx
  30. popl %ebx
  31.  
  32. pushl $delim
  33. pushl $sir
  34. call strtok
  35. popl %ebx
  36. popl %ebx
  37.  
  38. //strtok(NULL, " ")
  39. pushl $delim
  40. pushl $0
  41. call strtok
  42. popl %ebx
  43. popl %ebx
  44.  
  45. pushl %eax
  46. call atoi
  47. popl %ebx
  48.  
  49. movl %eax, n
  50.  
  51. //strtok(NULL, " ")
  52. pushl $delim
  53. pushl $0
  54. call strtok
  55. popl %ebx
  56. popl %ebx
  57.  
  58. pushl %eax
  59. call atoi
  60. popl %ebx
  61.  
  62. movl %eax, m
  63.  
  64. //index = n * m
  65. movl n, %eax
  66. xorl %edx, %edx
  67. mull m
  68. movl %eax, nr_elem
  69.  
  70. xorl %ecx, %ecx
  71.  
  72. et_for:
  73. cmp %ecx, nr_elem
  74. je cit_op
  75.  
  76. //strtok(NULL, " ")
  77. pushl %ecx
  78. pushl $delim
  79. pushl $0
  80. call strtok
  81. popl %ebx
  82. popl %ebx
  83. popl %ecx
  84.  
  85. pushl %ecx
  86. pushl %eax
  87. call atoi
  88. popl %ebx
  89. popl %ecx
  90.  
  91. movl $matrix, %edi
  92. movl %eax, (%edi, %ecx, 4)
  93.  
  94. incl %ecx
  95. jmp et_for
  96.  
  97. cit_op:
  98. //citeste let
  99. //strtok(NULL, " ")
  100. pushl $delim
  101. pushl $0
  102. call strtok
  103. popl %ebx
  104. popl %ebx
  105.  
  106. //citeste numele matircei
  107. //strtok(NULL, " ")
  108. pushl $delim
  109. pushl $0
  110. call strtok
  111. popl %ebx
  112. popl %ebx
  113.  
  114. //citeste operator/rot90d
  115. //strtok(NULL, " ")
  116. pushl $delim
  117. pushl $0
  118. call strtok
  119. popl %ebx
  120. popl %ebx
  121.  
  122. movl %eax, res
  123.  
  124. pushl %eax
  125. call atoi
  126. popl %ebx
  127.  
  128. cmp $0, %eax
  129. je rotire
  130.  
  131. movl %eax, op1
  132.  
  133. //citeste operatia
  134. //strtok(NULL, " ")
  135. pushl $delim
  136. pushl $0
  137. call strtok
  138. popl %ebx
  139. popl %ebx
  140.  
  141. movl %eax, res
  142. movl res, %esi
  143. xorl %ecx, %ecx
  144. xorl %eax, %eax
  145. movb (%esi, %ecx, 1), %al
  146.  
  147. xorl %ecx, %ecx
  148.  
  149. cmp $97, %al
  150. je adunare_for
  151. cmp $115, %al
  152. je scadere_for
  153. cmp $109, %al
  154. je inmultire_for
  155. cmp $100, %al
  156. je impartire_for
  157.  
  158. adunare_for:
  159. cmp nr_elem, %ecx
  160. je afis_rasp
  161.  
  162. movl $matrix, %edi
  163. movl op1, %eax
  164. addl %eax, (%edi, %ecx, 4)
  165.  
  166. incl %ecx
  167. jmp adunare_for
  168.  
  169. scadere_for:
  170. cmp nr_elem, %ecx
  171. je afis_rasp
  172.  
  173. movl $matrix, %edi
  174. movl op1, %eax
  175. subl %eax, (%edi, %ecx, 4)
  176.  
  177. incl %ecx
  178. jmp scadere_for
  179.  
  180. inmultire_for:
  181. cmp nr_elem, %ecx
  182. je afis_rasp
  183.  
  184. movl $matrix, %edi
  185. movl (%edi, %ecx, 4), %eax
  186. xorl %edx, %edx
  187. imull op1
  188. movl %eax, (%edi, %ecx, 4)
  189.  
  190. incl %ecx
  191. jmp inmultire_for
  192.  
  193. impartire_for:
  194. cmp nr_elem, %ecx
  195. je afis_rasp
  196.  
  197. cmp $0, op1
  198. jg op_poz
  199.  
  200. //operator negativ
  201. movl $matrix, %edi
  202. movl (%edi, %ecx, 4), %eax
  203.  
  204. cmp $0, %eax
  205. jge elempoz_opneg
  206.  
  207. //op neg si element din matrice negativ
  208. xorl %edx, %edx
  209. imull neg1
  210. xorl %edx, %edx
  211. idivl op1
  212. xorl %edx, %edx
  213. imull neg1
  214. movl %eax, (%edi, %ecx, 4)
  215.  
  216. incl %ecx
  217. jmp impartire_for
  218.  
  219. elempoz_opneg:
  220. //op neg si element din matrice pozitiv
  221. xorl %edx, %edx
  222. idivl op1
  223. movl %eax, (%edi, %ecx, 4)
  224.  
  225. incl %ecx
  226. jmp impartire_for
  227.  
  228. op_poz:
  229. //operator pozitiv
  230. movl $matrix, %edi
  231. movl (%edi ,%ecx, 4), %eax
  232.  
  233. cmp $0, %eax
  234. jge elempoz
  235.  
  236. //op poz si element din matrice negativ
  237. xorl %edx, %edx
  238. imull neg1
  239. xorl %edx, %edx
  240. idivl op1
  241. xorl %edx, %edx
  242. imull neg1
  243. movl %eax, (%edi, %ecx, 4)
  244.  
  245. incl %ecx
  246. jmp impartire_for
  247.  
  248. elempoz:
  249. //op poz si element din matrice pozitiv
  250. xorl %edx, %edx
  251. idivl op1
  252. movl %eax, (%edi, %ecx, 4)
  253.  
  254. incl %ecx
  255. jmp impartire_for
  256.  
  257. rotire:
  258. pushl m
  259. pushl $printnr
  260. call printf
  261. popl %ebx
  262. popl %ebx
  263.  
  264. pushl n
  265. pushl $printnr
  266. call printf
  267. popl %ebx
  268. popl %ebx
  269.  
  270. movl $0, columnIndex
  271. subl $1, n
  272. et_for_col:
  273. movl columnIndex, %ecx
  274. cmp m, %ecx
  275. je et_exit
  276.  
  277. movl n, %eax
  278. movl %eax, lineIndex
  279. et_for_linii:
  280. movl lineIndex, %ecx
  281. cmp $0, %ecx
  282. jl cont
  283.  
  284. //%eax := lineIndex * m + columnIndex
  285. movl lineIndex, %eax
  286. xorl %edx, %edx
  287. mull m
  288. addl columnIndex, %eax
  289.  
  290. movl $matrix, %edi
  291.  
  292. pushl (%edi, %eax, 4)
  293. pushl $printnr
  294. call printf
  295. popl %ebx
  296. popl %ebx
  297.  
  298. decl lineIndex
  299. jmp et_for_linii
  300.  
  301. cont:
  302. incl columnIndex
  303. jmp et_for_col
  304.  
  305. afis_rasp:
  306. pushl n
  307. pushl $printnr
  308. call printf
  309. popl %ebx
  310. popl %ebx
  311.  
  312. pushl m
  313. pushl $printnr
  314. call printf
  315. popl %ebx
  316. popl %ebx
  317.  
  318. movl $matrix, %edi
  319. xorl %ecx, %ecx
  320.  
  321. parc_mat:
  322. cmp nr_elem, %ecx
  323. je et_exit
  324.  
  325. pushl %ecx
  326. pushl (%edi, %ecx, 4)
  327. pushl $printnr
  328. call printf
  329. popl %ebx
  330. popl %ebx
  331. popl %ecx
  332.  
  333. incl %ecx
  334. jmp parc_mat
  335.  
  336. et_exit:
  337. pushl $newline
  338. call printf
  339. popl %ebx
  340.  
  341. movl $1, %eax
  342. xorl %ebx, %ebx
  343. int $0x80
  344.  
  345.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement