Guest User

Untitled

a guest
Jul 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. ;CALCULATRICE ASM v0.2
  2.  
  3. org 100h
  4.  
  5. ;Parametres entre
  6. mov ax, 43
  7. mov bx, 3
  8. mov cx, 6
  9. ;rapasser le binaire dans la pile en decimal ?
  10. ;0= Non | 1= Oui
  11. mov conVB,0
  12.  
  13.  
  14. ;Enregistrement A et B dans la pile
  15. push ax
  16. push bx
  17.  
  18. ;MENU
  19. cmp cx,1
  20. je addit
  21. cmp cx,2
  22. je soust
  23. cmp cx,3
  24. je multi
  25. cmp cx,4
  26. je divis
  27. cmp cx,5
  28. je puiss
  29. cmp cx,6
  30. je binai
  31. ;FIN MENU
  32.  
  33. ;OPERATIONS
  34. addit: ;bloc addition
  35. call addition
  36. jmp fin
  37.  
  38. soust: ;bloc soustraction
  39. call soustraction
  40. jmp fin
  41.  
  42. multi: ;bloc multiplication
  43. call multiplication
  44. jmp fin
  45.  
  46. divis: ;bloc division
  47. call division
  48. jmp fin
  49.  
  50. puiss: ;bloc puissance
  51. call puissance
  52. jmp fin
  53.  
  54. binai:;bloc binaire
  55. call binaire
  56. jmp fin
  57.  
  58. decim: ;bloc decimal
  59. call decimal
  60. jmp fin
  61. ;FINOPERATIONS
  62.  
  63.  
  64. fin:
  65. ret
  66. ;-------------------Fin ORG----------------------
  67.  
  68.  
  69.  
  70. ; ;-----------;
  71. ; ;PROCEDURES ;
  72. ; ;-----------;
  73. ;------------------------------------------------
  74.  
  75. addition proc
  76. ;bloc stack
  77. mov bp,sp
  78. mov ax,[bp+4]
  79. mov bx,[bp+2]
  80. ;fin bloc stack
  81.  
  82. add ax,bx ;ax=ax+bx
  83. ret
  84. addition endp
  85.  
  86. ;-------------------------------------------------
  87.  
  88. soustraction proc
  89. ;bloc stack
  90. mov bp,sp
  91. mov ax,[bp+4]
  92. mov bx,[bp+2]
  93. ;fin bloc stack
  94.  
  95. sub ax,bx ;ax=ax-bx
  96. ret
  97. soustraction endp
  98.  
  99. ;-------------------------------------------------
  100.  
  101. multiplication proc
  102. ;bloc stack
  103. mov bp,sp
  104. mov ax,[bp+4]
  105. mov bx,[bp+2]
  106. ;fin bloc stack
  107.  
  108. cmp ax,bx;Test ax>bx
  109. jg alt ;si oui aller altern
  110.  
  111. ;multiplication si ax<bx
  112. mov cx, ax
  113. mov ax,0
  114. debut: add ax,bx
  115. loop debut
  116. jmp finmulti
  117. ;Fin cas1
  118.  
  119. ;multiplication si ax>bx
  120. alt:mov cx, bx
  121. mov bx,0
  122.  
  123. debu2: add bx,ax
  124. loop debu2
  125. mov ax,bx
  126. ;fin cas2
  127.  
  128. finmulti:ret
  129. multiplication endp
  130.  
  131. ;-------------------------------------------------
  132.  
  133. division proc
  134. ;bloc stack
  135. mov bp,sp
  136. mov ax,[bp+4]
  137. mov bx,[bp+2]
  138. ;fin bloc stack
  139.  
  140. div bx ;ax=ax/bx
  141. ret
  142. division endp
  143. ;-------------------------------------------------
  144. puissance proc
  145. ;bloc stack
  146. mov bp,sp
  147. mov ax,[bp+4]
  148. mov bx,[bp+2]
  149. ;fin bloc stack
  150.  
  151.  
  152. ;test puissance particulieres.
  153. cmp bx,0
  154. je puisZero ;Car x^0=1 dans tous les cas
  155. cmp bx,1
  156. je finpuiss ;Car x^1=x dans tous les cas
  157. cmp bx,2
  158. je puisDEUX ;Probleme de boucle sinon
  159. ;fin test
  160.  
  161. ;preparation
  162. dec bx ;decrementation bx car sinon il fait la boucle 1x en trop
  163. push bx;enregistrement de bx pour compteur doubleB
  164. mov dx,ax;sauvegarde ax en dx
  165. mov cx,ax;maj compteur
  166. mov bx,ax;maj additioneur
  167. mov ax,0 ;mise a 0 pour l'addition
  168. jmp start;passage directe a la bcl multi
  169.  
  170. doubleB:
  171. push cx ;enregistrement de la valeur du compteur doubleB
  172. mov cx,dx ;maj compteur pour boucle "start"
  173. mov ax,0 ;mise a 0
  174.  
  175. ;boucle "start" ajoute bx a ax ,cx fois (bcl multi)
  176. start:
  177. add ax,bx
  178. loop start
  179.  
  180. mov bx,ax;passage du resultat en additioneur
  181. pop cx ;sortie valeur compteur doubleB
  182.  
  183. loop doubleB
  184.  
  185. jmp finpuiss
  186.  
  187. ;CAS PARTICULIERS
  188. puisZero: mov ax,1
  189. jmp finpuiss
  190.  
  191. puisDEUX: mov cx,ax;maj compteur
  192. mov bx,ax;maj additioneur
  193. mov ax,0 ;mise a 0 pour l'addition
  194.  
  195. startD:
  196. add ax,bx
  197. loop startD
  198. jmp finpuiss
  199. ;FINCASPARTICULIERS
  200. finpuiss: ret
  201. puissance endp
  202. ;-------------------------------------------------
  203. binaire proc
  204.  
  205. ;bloc stack
  206. mov bp,sp
  207. mov ax,[bp+4]
  208. mov bx,[bp+2]
  209. ;fin bloc stack
  210.  
  211. ;preparation
  212. mov bx,2
  213. mov cx,0
  214. mov dx,0
  215.  
  216.  
  217. startdec:
  218. ;On verifie si ax != 0
  219. cmp al,0
  220. je findec
  221.  
  222. diviz:
  223. mov dx,0
  224. div bx ;on divise ax soit ax/2
  225. inc cl;on incremente cl
  226.  
  227.  
  228. ;On verifie s'il y a un reste
  229. cmp dx,0
  230. je jumpE
  231. cmp dx,1
  232. je jumpNE
  233.  
  234. jumpE: push 0
  235. jmp startdec
  236. jumpNE:push 1
  237. jmp startdec
  238. ;fin "startdec"
  239.  
  240. findec:
  241. cmp ah,0
  242. jne diviz
  243.  
  244. ;Binaire dans la pile
  245.  
  246. cmp conVB,1
  247. call decimal
  248.  
  249.  
  250. mov sp,bp ;remet le pointeur sur l'adresse
  251. ret
  252. binaire endp
  253.  
  254. ;--------------------------
  255.  
  256. decimal proc
  257.  
  258. mov dx,0
  259. mov bx,2;binaire = ^2
  260. add sp,2
  261.  
  262. ;cx est egal au nombre de 0 et 1
  263. passDecimal:pop ax
  264. push cx ;on sors de la pile
  265. puissA:
  266. mul bx
  267. loop puissA
  268. pop cx
  269. add resultat,al
  270. loop passDecimal
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279. mov sp,bp ;on remet le stack pointer sur l'addresse de "binaire"
  280. ret
  281. decimal endp
  282. ;--------------------------
  283.  
  284.  
  285. ; VARIABLES
  286. conVB DB ?
  287. resultat DB ?
Add Comment
Please, Sign In to add comment