Napisal som program v Assemblery (pouzity MAMS). Ide o program ktory pocita slova okrem slova DOS, ale co sa mi absolutne nezda je rychlost, je to spomalene, myslim ze tymi nekonecnymi porovnavaniami. tu si ho mozte stiahnut saved.athost.net/p1 len pridajde koncovku exe.
kod:
.model small
.stack 100h
.data
zadaj_retazec db "Zadaj retazec: $"
koniec db "Koniec programu$",13,10
.code
;--------new line
proc new_line
mov ah,02h
mov dl,10d
int 21h
mov dl,13d
int 21h
ret
endp
;--------GET CHAR
proc get_char
mov ah,01h
int 21h
ret
endp get_char
;--------PUT_CHAR
proc put_char
mov ah,02h
int 21h
ret
endp
;--------PUT STRING
proc put_string
mov ah,09h
int 21h
ret
endp
start:
mov ax,@data
mov ds,ax
mov dx,offset zadaj_retazec ; Ulozime offset premennej
call put_string ; Vyvolame proceduru vytlacenia
mov cl,00 ; vynulovanie pocitadla slov
mov ch,00h ;priznak
; 01 - D medzera: 32
; 02 - O enter: 13
; 03 - S
; 04 - predchadzajuci znak 'medzera'
; 05 - predchadzajuci znak 'znak'
; zaciatok citania znakov
call get_char ; nacitame prvy znak
cmp al,32 ; ak je medzera ' '
jne prvy
mov ch,04h ;ulozime 04 = ' '
jmp prvy
citanie: ; citanie znakov
call get_char ; vstup znaku
prvy: ; navestie pre skok prvy znak
cmp al,32 ; ak je ' '
je medzera
cmp al,13 ; ak je <enter> - koniec programu
je finish
cmp al,'D' ; pociatok hladaneho slova
je z1
cmp ch,01h ; ak mame 'D'
je z2
cmp ch,02h ; ak mame 'O'
je z3
mov ch,05h ; nastavime 05, pretoze bol zadany iny znak
jmp citanie ; pokracujeme v nacitavani znakov
z1: ; ak je zadany znak 'D'
cmp ch,05h ; ak bol predchadzajuci znak znak
je citanie ; pokracuje v nacitavani
cmp ch,03h ; ak bol predchadzajuci znak 'S'
je mame_S
mov ch,01h ; znak D bol zadany
jmp citanie ; pokracuje v nacitavani
mame_S:
mov ch,05h ; nastavime 05, pretoze prechadzajuci znak je 'S'
jmp citanie
z2:
cmp al,'O' ; druhy zadany znak '0'
jne nerovna
mov ch,02h ; mame aj druhy znak
jmp citanie
nerovna:
mov ch,05h ; ak sa nerovna nastavime 05
jmp citanie
z3:
cmp al,'S' ; posledny zadany znak 'S'
jne nerovna2
mov ch,03h ; zapiseme, mame slovo
jmp citanie
nerovna2:
mov ch,05h ; priznak znak
jmp citanie
medzera: ; ak mame medzeru
cmp ch,04h ; predposledny znak ' '
je citanie
cmp ch,05h ; preposledny znak 'x' znak
je plus ; ak ano pocitame slovo
cmp ch,03h ; ak nacitany znak je 'S'
je mame_slovo
plus:
inc cl ; mame jedno slovo
mov ch,04h ; nastavime medzeru
jmp citanie
mame_slovo:
mov ch,04h ; nastavime medzeru
jmp citanie
; KONIEC NACITAVANIA (vstup <enter>)
finish:
cmp ch,00h ; ak ziadny vstup
je nemame_slovo
cmp ch,03h ; ak 'S'
jne ziadne_S ; ak nie je 'S'
mov ch,05h ; nemame slovo
jmp nemame_slovo
ziadne_S: ; mame znak
cmp ch,04h ; ak mame ' '
je nemame_slovo:
inc cl ; pripocitame slovo
mov ch,05h ; nastavime nulu
nemame_slovo:
call new_line
; KONIEC PROGRAMU
call new_line
mov ch,100
convert: ; cislo prevedieme do desiatkovej sustavy
mov ah,00h
mov al,cl
div ch
mov cl,ah
mov dl,al
add dl,"0"
call put_char
cmp ch,1
je end_of_write
mov ah,0h
mov al,ch
mov dl,10
div dl
mov ch,al
jmp convert
end_of_write:
call new_line
; oznam o skonceni programu zapricineny <enter>
mov dx,offset koniec
call put_string
; cakanie na <enter>
mov ah,00h
int 16h
; odosle signal OS o skonceni programu
mov ax, 4c00h
int 21h
end start
Fórum › Assembler
Pocitanie slov


Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 153 hostů
Podobná vlákna
Počítanie slov v Lazaruse — založil Tanka098
Výpis vět s počtem slov větším než je průměr slov ve větě — založil alex
Pocitanie 2. a 3. odmocniny — založil Tom@sQo
Počítanie znakov v reťazci — založil WhatsThiSs