| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- jumps
- ; ‚ ਠâ ?
- ; ‚¥àá¨ï 2. „ ë¥ ¨§ ä ©« input.txt
- ; …¨ª¥¥¢ ˆ.�. 2084/1 (Žà¨£¨ «)
- .286
- cseg segment byte public 'CODE'
- assume cs:cseg, ds:dseg, es:dseg
- start:
- mov ax, seg dseg
- mov es, ax
- mov ds, ax
- ;------------------------------
- mov ax, 3d00h
- mov dx, offset fname
- int 21h
- jc no_file
- push ax
- mov bp, 1 ; BP will hold ifWORK
- mov word ptr [LineNum], 1
- line_loop:
- pop bx
- mov cx, 1
- mov dx, offset from
- char_loop:
- mov ah, 3fh
- int 21h
- jc err_read
- mov si, dx
- test ax, ax
- jz eof
- cmp byte ptr ds:[si], 0ah
- je eol
- inc dx
- jmp char_loop
- eol: mov byte ptr ds:[si-1], 0
- push bx
- jmp work
- eof: mov byte ptr ds:[si], 0
- xor bp, bp ; We've reached end of file, so we don't need
- ; to loop again and ifWork = 0
- mov ah, 3eh
- int 21h
- ;---------------------------------
- ;
- work:
- cmp byte ptr [from], 0 ; Test input string to non-empty
- je new_line
- xor bx, bx ; BX will hold capitals count
- mov si, (offset from)-1
- cap_loop:
- inc si
- mov al, ds:[si]
- test al, al
- jz cap_end ; We've reached end of current line
- cmp al, 'A'
- jb cap_loop
- cmp al, 'Z'
- ja cap_loop
- ; Current character is capital
- inc bx
- jmp cap_loop
- ; We have reached end of line while searching for capitals
- cap_end:
- test bx, bx
- jz new_line ; We willn't treat 0 as even
- rcr bx, 1 ; Move least significant bit to CF (Carry)
- jc new_line ; If there is 1, so we've got an odd number of capitals
- ; Now we need to convert currnet line number
- ; to printable characters
- mov word ptr [strNum], '00'
- mov word ptr [strNum+2], '00'
- mov byte ptr [strNum+4], '0'
- mov si, offset strNum
- mov ax, LineNum
- mov bx, 10000
- xor dx, dx
- div bx
- add ds:[si], al
- inc si
- mov ax, dx ; dx holds remainder
- mov bx, 1000
- xor dx, dx
- div bx
- add ds:[si], al
- inc si
- mov ax, dx ; dx holds remainder
- mov bx, 100
- xor dx, dx
- div bx
- add ds:[si], al
- inc si
- mov ax, dx ; dx holds remainder
- mov bx, 10
- xor dx, dx
- div bx
- add ds:[si], al
- inc si
- add ds:[si], dx ; dx holds remainder
- mov ah, 9h
- mov dx, offset EVENline
- int 21h
- new_line:
- inc word ptr [LineNum]
- test bp, bp
- jz norm_out
- jmp line_loop ; Continue to work
- no_file:
- mov ah, 09h
- mov dx, offset no_file_str
- int 21h
- jmp norm_out
- err_read:
- mov ah, 3eh ; Close input file
- int 21h
- mov ah, 09h ; Write error message
- mov dx, offset err_read_str
- int 21h
- jmp short norm_out
- norm_out:
- mov ah, 4ch
- int 21h
- ends
- dseg segment para public 'DATA'
- fname db 'input.txt',0
- EVENLine db 'Count of capital characters is even on line '
- strNum db '00000',0dh,0ah,'$'
- no_file_str db 'Couldn''t open file input.txt$'
- err_read_str db 'Error while reading input.txt$'
- lineNum dw ?
- from db 200 dup (?)
- ends
- sseg segment stack
- db 200 dup (?)
- ends
- end start
|