Advertisement
Guest User

kod_mini_kalkulator_bagnutiy

a guest
Feb 11th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. FASM.
  2. boot.ASM:
  3.  
  4. org 0x7C00
  5.  
  6. start:
  7. cli
  8. xor ax,ax
  9. mov ds,ax
  10. mov es,ax
  11. mov ss,ax
  12. mov sp,0x7C00
  13. sti
  14. mov ax,2
  15. int 0x10
  16. mov dx,0
  17. call set_cursor_pos
  18. mov bp,msg
  19. mov cx,10
  20. call print_mes
  21. add dh,1
  22. call set_cursor_pos
  23. mov bp,con
  24. mov cx,14
  25. call print_mes
  26. cont:
  27. mov ah,0x10
  28. int 0x16
  29. cmp al,0xD
  30. jz kernel
  31. jmp cont
  32. kernel:
  33.  
  34. mov ax,0
  35. mov es,ax
  36. mov bx,0x7E00 ;dl'a chego????????!!?! mozhno zhe shto ugodno postavit'
  37. mov ch,0
  38. mov cl,2
  39. mov dh,0
  40. mov dl,0x80
  41. mov al,2
  42. mov ah,2
  43. int 0x13
  44. jmp 0x7E00
  45. print_mes:
  46. mov bl,3
  47. mov ax,0x1301
  48. int 0x10
  49. ret
  50. set_cursor_pos:
  51. mov ah,2
  52. xor bh,bh
  53. int 0x10
  54. ret
  55.  
  56. ;-------------------------------------------------
  57.  
  58. msg db 'loading...',0
  59. con db 'press Enter...',0
  60. finish: times 0x1FE-finish+start db 0
  61. db 0x55,0xAA
  62.  
  63. prog.ASM:
  64.  
  65. org 0x7E00
  66.  
  67. start:
  68. mov ax,2
  69. int 0x10
  70. mov dx,0
  71. call set_cursor_pos
  72. mov di,opr
  73. call print
  74. call input_sdec_word
  75. call print_endl
  76. mov bx,ax
  77. mov di,opr
  78. call print
  79. call input_sdec_word
  80. call print_endl
  81. push dx
  82. mov dx,bx
  83. mov bx,ax
  84. mov ax,dx
  85. pop dx
  86. mov di,diya
  87. call print
  88. call operac
  89. call print_endl
  90. mov di,vihodfraz
  91. call print
  92. call print_word_sdec
  93. call print_endl
  94. mov di,pak
  95. call print
  96. mov ah,0x00
  97. int 0x16
  98. call print_endl
  99. jmp start
  100.  
  101. ;-------------------------------------------------
  102.  
  103. print:
  104. push ax
  105. push bx
  106.  
  107. mov ah,0x0E
  108. mov bh,0x00
  109. putch_lp:
  110. mov al,byte[di]
  111. inc di
  112. test al,al
  113. jz print_exit
  114. inc dl
  115. int 0x10
  116. jmp putch_lp
  117. print_exit:
  118. pop bx
  119. pop ax
  120. ret
  121.  
  122. print_endl:
  123. push di
  124. mov di,endline
  125. call print
  126. pop di
  127. mov dl,0
  128. inc dh
  129. call set_cursor_pos
  130. ret
  131.  
  132. ;-------------------------------------------------
  133.  
  134. word_to_udec:
  135. push cx
  136. push dx
  137. push bx
  138. xor cx,cx
  139. mov bx,10
  140. wu_lup1:
  141. xor dx,dx
  142. div bx
  143. add dx,'0'
  144. push dx
  145. inc cx
  146. test ax,ax
  147. jnz wu_lup1
  148. wu_lup2:
  149. pop dx
  150. mov [di],dl
  151. inc di
  152. loop wu_lup2
  153.  
  154. pop bx
  155. pop dx
  156. pop cx
  157. ret
  158.  
  159. print_word_sdec:
  160. push di
  161. mov di,buffer
  162. push di
  163. call word_to_sdec
  164. mov byte[di],0
  165. pop di
  166. call print
  167. pop di
  168. ret
  169.  
  170. word_to_sdec:
  171. push ax
  172. test ax,ax
  173. jns wtsd_nosign
  174. mov byte[di],'-'
  175. inc di
  176. neg ax
  177. wtsd_nosign:
  178. call word_to_udec
  179. pop ax
  180. ret
  181.  
  182. ;-------------------------------------------------
  183.  
  184. input:
  185. push ax
  186. push bx
  187. push cx
  188. xor si,si
  189. input_jmp:
  190.  
  191. mov ah,0x10
  192. int 0x16
  193. cmp ah,0xE
  194. jz delete_symbol
  195. cmp al,0xD
  196. jz input_end
  197.  
  198. mov [inp_buf+si],al
  199. inc si
  200. mov ah,9
  201. mov bl,5 ;atribut
  202. mov cx,1
  203. int 0x10
  204. add dl,1
  205. call set_cursor_pos
  206. jmp input_jmp
  207. delete_symbol:
  208. cmp dl,0
  209. jz input
  210. sub dl,1
  211. call set_cursor_pos
  212. mov al,0x20 ;probel
  213. mov [inp_buf+si],al
  214. dec si
  215. mov ah,9
  216. mov bl,7
  217. mov cx,1
  218. int 0x10
  219. jmp input_jmp
  220. input_end:
  221. pop cx
  222. pop bx
  223. pop ax
  224. ret
  225.  
  226. ;-------------------------------------------------
  227.  
  228. input_sdec_word:
  229. push bx
  230. push cx
  231.  
  232. call input
  233. mov cx,si
  234. mov di,inp_buf
  235. call to_sdec_word
  236. isw_exit:
  237. pop cx
  238. pop bx
  239. ret
  240.  
  241. to_sdec_word:
  242. push bx
  243. push dx
  244.  
  245. mov bl,byte[di]
  246. cmp bl,'-'
  247. jnz tsw_unsign
  248. inc di
  249. dec cx
  250. tsw_unsign:
  251. call to_udec_word
  252. jc tsw_error
  253. mov di,inp_buf
  254. mov bl,byte[di]
  255. cmp bl,'-'
  256. jz tsw_minus
  257. cmp ax,32767
  258. ja tsw_error
  259. jmp tsw_exit
  260. tsw_minus:
  261. cmp ax,32768
  262. ja tsw_error
  263. neg ax
  264. jmp tsw_exit
  265. tsw_error:
  266. call print_endl
  267. mov di,errorline
  268. call print
  269. xor ax,ax
  270. tsw_exit:
  271. pop dx
  272. pop bx
  273. ret
  274.  
  275. to_udec_word:
  276. push cx
  277. push dx
  278. push bx
  279. push si
  280. push di
  281.  
  282. mov si,10
  283. xor ax,ax
  284. xor bx,bx
  285. xor dx,dx
  286. tuw_lp:
  287. mov bl,[di]
  288. inc di
  289. cmp bl,'0'
  290. jl tuw_error
  291. cmp bl,'9'
  292. jg tuw_error
  293. sub bl,'0'
  294. mul si
  295. jc tuw_error
  296. add ax,bx
  297. loop tuw_lp
  298. jmp tuw_exit
  299. tuw_error:
  300. call print_endl
  301. mov di,errorline
  302. call print
  303. xor ax,ax
  304. tuw_exit:
  305. pop di
  306. pop si
  307. pop bx
  308. pop dx
  309. pop cx
  310. ret
  311.  
  312. ;-------------------------------------------------
  313.  
  314. operac:
  315. push di
  316.  
  317. call input
  318.  
  319. push dx
  320.  
  321. mov di,inp_buf
  322. mov dl,byte[di]
  323. cmp dl,'+'
  324. jz op_plus
  325. cmp dl,'-'
  326. jz op_minus
  327. cmp dl,'*'
  328. jz op_umn
  329. cmp dl,'/'
  330. jz op_del
  331. jmp operac_end
  332. op_plus:
  333. add ax,bx
  334. jmp operac_end
  335. op_minus:
  336. sub ax,bx
  337. jmp operac_end
  338. op_umn:
  339. imul bx
  340. jmp operac_end
  341. op_del:
  342. idiv bx
  343. operac_end:
  344. pop dx
  345. pop di
  346. ret
  347.  
  348. ;-------------------------------------------------
  349.  
  350. set_cursor_pos:
  351. push bx
  352. push ax
  353. mov ah,2
  354. xor bh,bh
  355. int 0x10
  356. pop ax
  357. pop bx
  358. ret
  359.  
  360. ;-------------------------------------------------
  361.  
  362. inp_buf rb 8
  363. buffer rb 8
  364. errorline db 'error...',0
  365. pak db 'press any key...',0
  366. opr db 'operand: ',0
  367. diya db 'operation: ',0
  368. vihodfraz db 'chislo: ',0
  369. endline db 13,10,0
  370.  
  371. sbor.ASM:
  372.  
  373. macro align value { db value-1 - ($ + value-1) mod (value) dup 0 }
  374. HEADS = 1
  375. SPT = 2
  376. Begin:
  377. file "boot.bin",512
  378. file "prog.bin"
  379. align 512
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement