solnce.as2 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. jumps
  2. ; ‚ à¨ ­â ?
  3. ; ‚¥àá¨ï 2. „ ­­ë¥ ¨§ ä ©«  input.txt
  4. ; …­¨ª¥¥¢ ˆ.�. 2084/1 (Žà¨£¨­ «)
  5. .286
  6. cseg segment byte public 'CODE'
  7. assume cs:cseg, ds:dseg, es:dseg
  8. start:
  9. mov ax, seg dseg
  10. mov es, ax
  11. mov ds, ax
  12. ;------------------------------
  13. mov ax, 3d00h
  14. mov dx, offset fname
  15. int 21h
  16. jc no_file
  17. push ax
  18. mov bp, 1 ; BP will hold ifWORK
  19. mov word ptr [LineNum], 1
  20. line_loop:
  21. pop bx
  22. mov cx, 1
  23. mov dx, offset from
  24. char_loop:
  25. mov ah, 3fh
  26. int 21h
  27. jc err_read
  28. mov si, dx
  29. test ax, ax
  30. jz eof
  31. cmp byte ptr ds:[si], 0ah
  32. je eol
  33. inc dx
  34. jmp char_loop
  35. eol: mov byte ptr ds:[si-1], 0
  36. push bx
  37. jmp work
  38. eof: mov byte ptr ds:[si], 0
  39. xor bp, bp ; We've reached end of file, so we don't need
  40. ; to loop again and ifWork = 0
  41. mov ah, 3eh
  42. int 21h
  43. ;---------------------------------
  44. ;
  45. work:
  46. cmp byte ptr [from], 0 ; Test input string to non-empty
  47. je new_line
  48. xor bx, bx ; BX will hold capitals count
  49. mov si, (offset from)-1
  50. cap_loop:
  51. inc si
  52. mov al, ds:[si]
  53. test al, al
  54. jz cap_end ; We've reached end of current line
  55. cmp al, 'A'
  56. jb cap_loop
  57. cmp al, 'Z'
  58. ja cap_loop
  59. ; Current character is capital
  60. inc bx
  61. jmp cap_loop
  62. ; We have reached end of line while searching for capitals
  63. cap_end:
  64. test bx, bx
  65. jz new_line ; We willn't treat 0 as even
  66. rcr bx, 1 ; Move least significant bit to CF (Carry)
  67. jc new_line ; If there is 1, so we've got an odd number of capitals
  68. ; Now we need to convert currnet line number
  69. ; to printable characters
  70. mov word ptr [strNum], '00'
  71. mov word ptr [strNum+2], '00'
  72. mov byte ptr [strNum+4], '0'
  73. mov si, offset strNum
  74. mov ax, LineNum
  75. mov bx, 10000
  76. xor dx, dx
  77. div bx
  78. add ds:[si], al
  79. inc si
  80. mov ax, dx ; dx holds remainder
  81. mov bx, 1000
  82. xor dx, dx
  83. div bx
  84. add ds:[si], al
  85. inc si
  86. mov ax, dx ; dx holds remainder
  87. mov bx, 100
  88. xor dx, dx
  89. div bx
  90. add ds:[si], al
  91. inc si
  92. mov ax, dx ; dx holds remainder
  93. mov bx, 10
  94. xor dx, dx
  95. div bx
  96. add ds:[si], al
  97. inc si
  98. add ds:[si], dx ; dx holds remainder
  99. mov ah, 9h
  100. mov dx, offset EVENline
  101. int 21h
  102. new_line:
  103. inc word ptr [LineNum]
  104. test bp, bp
  105. jz norm_out
  106. jmp line_loop ; Continue to work
  107. no_file:
  108. mov ah, 09h
  109. mov dx, offset no_file_str
  110. int 21h
  111. jmp norm_out
  112. err_read:
  113. mov ah, 3eh ; Close input file
  114. int 21h
  115. mov ah, 09h ; Write error message
  116. mov dx, offset err_read_str
  117. int 21h
  118. jmp short norm_out
  119. norm_out:
  120. mov ah, 4ch
  121. int 21h
  122. ends
  123. dseg segment para public 'DATA'
  124. fname db 'input.txt',0
  125. EVENLine db 'Count of capital characters is even on line '
  126. strNum db '00000',0dh,0ah,'$'
  127. no_file_str db 'Couldn''t open file input.txt$'
  128. err_read_str db 'Error while reading input.txt$'
  129. lineNum dw ?
  130. from db 200 dup (?)
  131. ends
  132. sseg segment stack
  133. db 200 dup (?)
  134. ends
  135. end start