Advertisement
Cosmin3105

1

Nov 26th, 2021
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. .data
  2. sirhex: .space 100
  3.  
  4. codOp: .long 0
  5.  
  6. nr: .space 4
  7. cifra2: .long 0
  8. cifra: .long 0
  9.  
  10. nrPoz: .long 0
  11. nrNeg: .long 0
  12. op: .long 0
  13. var: .long 0
  14.  
  15. formatScanf: .asciz "%s"
  16.  
  17. newline: .asciz "\n"
  18.  
  19. //neg: .long -1
  20. minus: .asciz "-"
  21.  
  22. let: .asciz "let "
  23. sum: .asciz "add "
  24. dif: .asciz "sub "
  25. inmul: .asciz "mul "
  26. imp: .asciz "div "
  27.  
  28. afisVariabila: .asciz "%c "
  29. afisNumar: .asciz "%d "
  30.  
  31. .text
  32.  
  33. .global main
  34.  
  35. main:
  36. //scanf("%s", &s)
  37. pushl $sirhex
  38. pushl $formatScanf
  39. call scanf
  40. popl %ebx
  41. popl %ebx
  42.  
  43. movl $sirhex, %edi
  44. movl $0, %ecx
  45.  
  46. et_for:
  47. //identificator
  48. movb (%edi, %ecx, 1), %al
  49. cmp $0, %al
  50. je et_exit
  51.  
  52. movl $0, nrPoz
  53. movl $0, nrNeg
  54. movl $0, op
  55. movl $0, var
  56.  
  57. cmp $56, %al #8 -> numar pozitiv
  58. je nr_poz
  59.  
  60. cmp $57, %al #9 -> numar negativ
  61. je nr_neg
  62.  
  63. cmp $67, %al #C -> operatie
  64. je operatie
  65.  
  66. cmp $65, %al #A -> variabila
  67. je variabila
  68.  
  69. nr_poz:
  70. movl $1, nrPoz
  71. jmp cont
  72.  
  73. nr_neg:
  74. movl $1, nrNeg
  75. jmp cont
  76.  
  77. operatie:
  78. movl $1, op
  79. jmp cont
  80.  
  81. variabila:
  82. movl $1, var
  83. jmp cont
  84.  
  85. cont:
  86. incl %ecx
  87.  
  88. movl $0, cifra2
  89. movl $0, codOp
  90.  
  91. movb (%edi, %ecx, 1), %al
  92. cmp $0, %al
  93. je et_exit
  94.  
  95.  
  96. calcOp:
  97. movl %eax, cifra
  98. pushl %eax
  99.  
  100. cmp $1, cifra2
  101. je adaug1
  102.  
  103. movl $16, %eax
  104. jmp compara
  105.  
  106. adaug1:
  107. movl $1, %eax
  108.  
  109. compara:
  110. cmp $48, cifra
  111. je cif0
  112. cmp $49, cifra
  113. je cif1
  114. cmp $50, cifra
  115. je cif2
  116. cmp $51, cifra
  117. je cif3
  118. cmp $52, cifra
  119. je cif4
  120. cmp $53, cifra
  121. je cif5
  122. cmp $54, cifra
  123. je cif6
  124. cmp $55, cifra
  125. je cif7
  126. cmp $56, cifra
  127. je cif8
  128. cmp $57, cifra
  129. je cif9
  130. cmp $65, cifra
  131. je cif10
  132. cmp $66, cifra
  133. je cif11
  134. cmp $67, cifra
  135. je cif12
  136. cmp $68, cifra
  137. je cif13
  138. cmp $69, cifra
  139. je cif14
  140. cmp $70, cifra
  141. je cif15
  142.  
  143. cif0:
  144. movl $0, nr
  145. mull nr
  146. jmp cont2
  147. cif1:
  148. movl $1, nr
  149. mull nr
  150. jmp cont2
  151. cif2:
  152. movl $2, nr
  153. mull nr
  154. jmp cont2
  155. cif3:
  156. movl $3, nr
  157. mull nr
  158. jmp cont2
  159. cif4:
  160. movl $4, nr
  161. mull nr
  162. jmp cont2
  163. cif5:
  164. movl $5, nr
  165. mull nr
  166. jmp cont2
  167. cif6:
  168. movl $6, nr
  169. mull nr
  170. jmp cont2
  171. cif7:
  172. movl $7, nr
  173. mull nr
  174. jmp cont2
  175. cif8:
  176. movl $8, nr
  177. mull nr
  178. jmp cont2
  179. cif9:
  180. movl $9, nr
  181. mull nr
  182. jmp cont2
  183. cif10:
  184. movl $10, nr
  185. mull nr
  186. jmp cont2
  187. cif11:
  188. movl $11, nr
  189. mull nr
  190. jmp cont2
  191. cif12:
  192. movl $12, nr
  193. mull nr
  194. jmp cont2
  195. cif13:
  196. movl $13, nr
  197. mull nr
  198. jmp cont2
  199. cif14:
  200. movl $14, nr
  201. mull nr
  202. jmp cont2
  203. cif15:
  204. movl $15, nr
  205. mull nr
  206. jmp cont2
  207.  
  208. cont2:
  209. addl %eax, codOp
  210. popl %eax
  211.  
  212. cmp $1, cifra2 #verific daca sunt la prima sau a doua cifra hex din codificarea operatiei
  213. je afOp #daca sunt la a doua cifra afisez operatia
  214.  
  215. movl $1, cifra2
  216.  
  217. incl %ecx
  218.  
  219. movb (%edi, %ecx, 1), %al
  220. cmp $0, %al
  221. je et_exit
  222.  
  223. jmp calcOp #adaug si a doua cifra hex la coficarea operatiei
  224.  
  225. afOp:
  226. cmp $1, nrPoz
  227. je afNrPoz
  228. cmp $1, nrNeg
  229. je afNrNeg
  230. cmp $1, op
  231. je afisOp
  232. cmp $1, var
  233. je afVar
  234.  
  235. afNrPoz:
  236. //printf("%d ", codOp)
  237. pushl %eax
  238. pushl %ecx
  239. pushl codOp
  240. pushl $afisNumar
  241. call printf
  242. popl %ebx
  243. popl %ebx
  244. popl %ecx
  245. popl %eax
  246. jmp cont3
  247.  
  248. afNrNeg:
  249. //pushl %eax
  250. //movl codOp, %eax
  251. //imull neg
  252. //movl %eax, codOp
  253. //popl %eax
  254.  
  255. pushl %eax
  256. pushl %ecx
  257. pushl $minus
  258. call printf
  259. popl %ebx
  260. popl %ecx
  261. popl %eax
  262.  
  263. //printf("%d ", codOp)
  264. pushl %eax
  265. pushl %ecx
  266. pushl codOp
  267. pushl $afisNumar
  268. call printf
  269. popl %ebx
  270. popl %ebx
  271. popl %ecx
  272. popl %eax
  273. jmp cont3
  274.  
  275. afisOp:
  276. cmp $0, codOp
  277. je afLet
  278. cmp $1, codOp
  279. je afAdd
  280. cmp $2, codOp
  281. je afSub
  282. cmp $3, codOp
  283. je afMul
  284. cmp $4, codOp
  285. je afDiv
  286.  
  287. afLet:
  288. pushl %eax
  289. pushl %ecx
  290. pushl $let
  291. call printf
  292. popl %ebx
  293. popl %ecx
  294. popl %eax
  295.  
  296. jmp cont3
  297.  
  298. afAdd:
  299. pushl %eax
  300. pushl %ecx
  301. pushl $sum
  302. call printf
  303. popl %ebx
  304. popl %ecx
  305. popl %eax
  306.  
  307. jmp cont3
  308.  
  309. afSub:
  310. pushl %eax
  311. pushl %ecx
  312. pushl $dif
  313. call printf
  314. popl %ebx
  315. popl %ecx
  316. popl %eax
  317.  
  318. jmp cont3
  319.  
  320. afMul:
  321. pushl %eax
  322. pushl %ecx
  323. pushl $inmul
  324. call printf
  325. popl %ebx
  326. popl %ecx
  327. popl %eax
  328.  
  329. jmp cont3
  330.  
  331. afDiv:
  332. pushl %eax
  333. pushl %ecx
  334. pushl $imp
  335. call printf
  336. popl %ebx
  337. popl %ecx
  338. popl %eax
  339.  
  340. jmp cont3
  341.  
  342. afVar:
  343. //printf("%c ", codOp)
  344. pushl %eax
  345. pushl %ecx
  346. pushl codOp
  347. pushl $afisVariabila
  348. call printf
  349. popl %ebx
  350. popl %ebx
  351. popl %ecx
  352. popl %eax
  353. jmp cont3
  354.  
  355. cont3:
  356. incl %ecx
  357.  
  358. jmp et_for
  359.  
  360. et_exit:
  361. //printf("\n")
  362. pushl %ecx
  363. pushl $newline
  364. call printf
  365. popl %ebx
  366. popl %ecx
  367.  
  368. movl $1, %eax
  369. xorl %ebx, %ebx
  370. int $0x80
  371.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement