Advertisement
Sauka1337

Untitled

Mar 11th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. org 100h
  2.  
  3. jmp start
  4.  
  5. array db 1, -2, -4, 5, -5, -3, 9, 20
  6. size = $ - array
  7. mess1 db 'Sum of positive elements = $'
  8. mess2 db 'Count of negative elements = $'
  9. nextLine db '', 13, 10, '$'
  10.  
  11. start:
  12.  
  13. mov ah, 9
  14. mov dx, mess2
  15. int 21h
  16.  
  17. mov si, array ; SI = óêàçàòåëü íà ìàññèâ
  18. mov cx, size ; CX = äëèíà ìàññèâà/öèêëà
  19. xor ax, ax ; î÷èùàåì ÀÕ (ñþäà áóäåì ÷èòàòü)
  20. xor dx, dx ;Äëÿ êîë-âà ìèíóñîâûõ
  21. xor bx, bx ; î÷èùàåì ÂÕ (çäåñü áóäåò ñóììà)
  22. mov dl, 1
  23.  
  24. Cycle:
  25. lodsb
  26. test al, al
  27. jns M1
  28. inc bx
  29. loop Cycle
  30.  
  31. M1:
  32. add dx, ax
  33.  
  34. loop Cycle ;Èäåì íà ñëåäóþùóþ èòåðàöèþ
  35.  
  36. mov ax, bx ; âûâîäèì ñóììó íà ýêðàí
  37. mov bx, 10 ; ñèñòåìà ñ÷èñëåíèÿ 10-òè÷íàÿ
  38. call hex2asc ; çîâ¸ì ôóíêöèþ âûâîäà ÷èñåë íà ýêðàí!
  39.  
  40. dec dx
  41. mov bx, dx
  42.  
  43. mov ah, $09
  44. mov dx, nextLine
  45. int 21h
  46.  
  47. mov ah, $09
  48. mov dx, mess1
  49. int 21h
  50.  
  51.  
  52. mov ax, bx ; âûâîäèì ñóììó íà ýêðàí
  53. mov bx, 10 ; ñèñòåìà ñ÷èñëåíèÿ 10-òè÷íàÿ
  54. call hex2asc ; çîâ¸ì ôóíêöèþ âûâîäà ÷èñåë íà ýêðàí!
  55.  
  56.  
  57. Exit:
  58. mov ah, $08 ; AH=8 - ôóíêöèÿ DOS äëÿ ÷òåíèÿ ñèìâîëà áåç ýõà
  59. int 21h ; Âûçûâàåì ïðåðûâàíèå DOS
  60. ret ; Âîçâðàùàåìñÿ èç ïðîöåäóðû
  61.  
  62. hex2asc: ; Ôóíêöèÿ ïåðåâîäèò ÷èñëà â ñèìâîëû
  63. pusha ; Âõîä: ÀÕ = ÷èñëî, BX = ñèñòåìà ñ÷èñëåíèÿ
  64. xor cx, cx ; Âûõîä: íà ýêðàíå
  65. isDiv:
  66. xor dx, dx
  67. div bx
  68. push dx
  69. inc cx
  70. or ax, ax
  71. jnz isDiv
  72. isOut:
  73. pop ax
  74. cmp al, 9
  75. jle noHex
  76. add al, 7
  77. noHex:
  78. add al, 30h
  79. int 29h
  80. loop isOut
  81. popa
  82. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement