Advertisement
Guest User

Untitled

a guest
May 31st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .8086
  2.  
  3. .MODEL TINY
  4.  
  5. .data
  6.  
  7. total dw 0
  8.  
  9. nnnS dw 10
  10.  
  11. TEN db 10
  12.  
  13. temp dw 0
  14.  
  15. inputcccS db 0Ah,0Dh, "cccS: ", "$"
  16.  
  17. inputdddS db 0Ah,0Dh, "dddS: ", "$"
  18.  
  19. inputArr db "Fill the array with 10 numbers from the range[0;65535]: ", "$"
  20.  
  21. whiteSpace db 0Ah,0Dh,">>> ", "$"
  22.  
  23. cout db 0Ah,0Dh,"<<< ", "$"
  24.  
  25. ERRORMESSAGE db 0Dh,0Ah,"Incorrect number!","$"
  26.  
  27. RESULTMESSAGE db 0Dh, 0Ah, "TOTAL: ", "$"
  28.  
  29. endline db "", 0Ah,0Dh, "$"
  30.  
  31. PARAMS LABEL BYTE
  32.  
  33. MAXLEN DB 7
  34.  
  35. ACTLEN DB ?
  36.  
  37. STRING DB 7 DUP('$'),'$'
  38.  
  39. .data?
  40.  
  41. arrra dw 10 dup(?)
  42.  
  43. cccS dw ?
  44.  
  45. dddS dw ?
  46.  
  47. .code
  48.  
  49. org 100h
  50.  
  51. MAIN:
  52.  
  53. ;----------------------------------------------------------------
  54.  
  55. ;--> INPUT array & CONVERT
  56.  
  57. mov ah, 9h
  58.  
  59. mov dx, offset inputArr
  60.  
  61. int 21h
  62.  
  63. mov bx, offset arrra
  64.  
  65. mov cx, nnnS
  66.  
  67. input_arr:
  68.  
  69. mov temp, cx
  70.  
  71. mov ah, 9h
  72.  
  73. mov dx, offset whitespace
  74.  
  75. int 21h
  76.  
  77. mov ah, 0Ah
  78.  
  79. mov dx, offset PARAMS
  80.  
  81. int 21h
  82.  
  83. xor dx, dx
  84.  
  85. call convert
  86.  
  87. cmp dx, 1
  88.  
  89. JE ERROR
  90.  
  91. mov [bx], ax
  92.  
  93. add bx, 2
  94.  
  95. mov cx, temp
  96.  
  97. loop input_arr
  98.  
  99. ;----------------------------------------------------------------
  100.  
  101. mov ah, 9h
  102.  
  103. mov dx, offset endline
  104.  
  105. int 21h
  106.  
  107. ;----------------------------------------------------------------
  108.  
  109. ;--> INPUT cccS & dddS & CONVERT
  110.  
  111. ;--> cccS
  112.  
  113. mov ah, 9h
  114.  
  115. mov dx, offset inputcccS
  116.  
  117. int 21h
  118.  
  119. mov ah, 0Ah
  120.  
  121. mov dx, offset PARAMS
  122.  
  123. int 21h
  124.  
  125. xor dx, dx
  126.  
  127. call convert
  128.  
  129. cmp dx, 1
  130.  
  131. JE ERROR
  132.  
  133. mov cccS, ax
  134.  
  135. ;--> dddS
  136.  
  137. mov ah, 9h
  138.  
  139. mov dx, offset inputdddS
  140.  
  141. int 21h
  142.  
  143. mov ah, 0Ah
  144.  
  145. mov dx, offset PARAMS
  146.  
  147. int 21h
  148.  
  149. xor dx, dx
  150.  
  151. call convert
  152.  
  153. cmp dx, 1
  154.  
  155. JE ERROR
  156.  
  157. mov dddS, ax
  158.  
  159. ;----------------------------------------------------------------
  160.  
  161. ;----------------------------------------------------------------
  162.  
  163. call show_arr
  164.  
  165. JMP process
  166.  
  167. ERROR:
  168.  
  169. call errmsg
  170.  
  171. JMP EXIT
  172.  
  173. ;----------------------------------------------------------------
  174.  
  175. ;--> COUNT TOTAL
  176.  
  177. process:
  178.  
  179. mov cx, nnnS
  180.  
  181. mov bx, offset arrra
  182.  
  183. count:
  184.  
  185. mov ax, [bx]
  186.  
  187. cmp ax, cccS
  188.  
  189. JB BAD
  190.  
  191. cmp ax, dddS
  192.  
  193. JA BAD
  194.  
  195. add total, 1
  196.  
  197. BAD:
  198.  
  199. add bx, 2
  200.  
  201. loop count
  202.  
  203. ;--> OUTPUT TOTAL
  204.  
  205. OUTPUT:
  206.  
  207. mov ah, 9h
  208.  
  209. lea dx, RESULTMESSAGE
  210.  
  211. int 21h
  212.  
  213. mov ax, total
  214.  
  215. mov cx, 10
  216.  
  217. call Show_AX
  218.  
  219. JMP EXIT
  220.  
  221. EXIT: ret
  222.  
  223. ;----------------------------------------------------------------
  224.  
  225. ; ----> PROCEDURE: CONVERT STRING TO UNSIGNED INT
  226.  
  227. convert:
  228.  
  229. push bx
  230.  
  231. push cx
  232.  
  233. push di
  234.  
  235. xor ax, ax ;обнуляется регистр
  236.  
  237. lea di, STRING ;di - индексный регистр
  238.  
  239. xor ch, ch ;обнуляется регистр
  240.  
  241. mov cl, ACTLEN ;Число цифр в буфере
  242.  
  243. xor bh, bh ;обнуляется регистр
  244.  
  245. m1:
  246.  
  247. mul TEN ;умножить ax на 10
  248.  
  249. mov bl, [di] ;к произвдению добавить число
  250.  
  251. cmp bl, 30h ;сравнение
  252.  
  253. JL BADINPUTING ;если меньше '0'
  254.  
  255. cmp bl, 39h ;сравнение
  256.  
  257. JG BADINPUTING ;если больше '9'
  258.  
  259. sub bl, 30h ;отнять 30h
  260.  
  261. add ax, bx ;добачить число к сумме ax
  262.  
  263. inc di ;инкремент di
  264.  
  265. loop m1 ;повтор цикла
  266.  
  267. JMP CONT
  268.  
  269. BADINPUTING:
  270.  
  271. mov dx, 1
  272.  
  273. CONT:
  274.  
  275. pop di
  276.  
  277. pop cx
  278.  
  279. pop bx
  280.  
  281. ret
  282.  
  283. ;----------------------------------------------------------------
  284.  
  285. ; ----> PROCEDURE: OUTPUT ERRORMESSAGE
  286.  
  287. errmsg:
  288.  
  289. mov ah, 9h
  290.  
  291. lea dx, ERRORMESSAGE
  292.  
  293. int 21h
  294.  
  295. ret
  296.  
  297. ;----------------------------------------------------------------
  298.  
  299. ; ----> PROCEDURE: CONVERT UNSIGNED INT TO STRING
  300.  
  301. Show_AX:
  302.  
  303. push ax
  304.  
  305. push bx
  306.  
  307. push cx
  308.  
  309. push dx
  310.  
  311. push di
  312.  
  313. xor di, di ; di - кол. цифр в числе
  314.  
  315. @@Conv:
  316.  
  317. xor dx, dx
  318.  
  319. div cx ; dl = num mod 10
  320.  
  321. add dl, '0' ; перевод в символьный формат
  322.  
  323. inc di
  324.  
  325. push dx ; складываем в стэк
  326.  
  327. or ax, ax
  328.  
  329. jnz @@Conv
  330.  
  331. ; выводим из стэка на экран
  332.  
  333. @@Show:
  334.  
  335. pop dx ; dl = очередной символ
  336.  
  337. mov ah, 2 ; ah - функция вывода символа на экран
  338.  
  339. int 21h
  340.  
  341. dec di ; повторяем пока di<>0
  342.  
  343. jnz @@Show
  344.  
  345. pop di
  346.  
  347. pop dx
  348.  
  349. pop cx
  350.  
  351. pop bx
  352.  
  353. pop ax
  354.  
  355. ret
  356.  
  357. ;----------------------------------------------------------------
  358.  
  359. show_arr:
  360.  
  361. mov ah, 9h
  362.  
  363. mov dx, offset endline
  364.  
  365. int 21h
  366.  
  367. mov bx, offset arrra
  368.  
  369. mov cx, nnnS
  370.  
  371. outputarr:
  372.  
  373. mov temp, cx
  374.  
  375. mov ah, 9h
  376.  
  377. mov dx, offset whitespace
  378.  
  379. int 21h
  380.  
  381. mov ax, [bx]
  382.  
  383. mov cx, 10
  384.  
  385. call Show_AX
  386.  
  387. add bx, 2
  388.  
  389. mov cx, temp
  390.  
  391. loop outputarr
  392.  
  393. mov ah, 9h
  394.  
  395. mov dx, offset endline
  396.  
  397. int 21h
  398.  
  399. ret
  400.  
  401. ;----------------------------------------------------------------
  402.  
  403. end MAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement