masm - Assembly Language program stuck in an infinite loop -


my program seems stuck in loop after program prompts user input paragraph.

title csc221a4  (csc2214.asm)  include irvine32.inc  .data mainmenu1   byte    " ", 0ah, 0ah, 0ah             byte    "       main menu           ", 0ah             byte    " 1. count , display number of characters (press 1)   ", 0ah, 0ah             byte    " 2. count , display number of words (press 2) ", 0ah, 0ah             byte    " 3. count , display number of sentences (press 3) ", 0ah, 0ah             byte    " 4. count , display numbers of letters equal 'n' or 'n'  (press 4)", 0ah, 0ah             byte    " 5. count , display number of capital letters (press 5) ", 0ah, 0ah             byte    " 6. count , display number of vowels (press 6) ", 0ah, 0ah  prompt1     byte " ", 0ah, 0ah             byte "please enter paragraph. press $ end.",0ah, 0ah, 0 prompt2     byte " ", 0ah, 0ah             byte " '$' entered. paragraph calculate.", 0ah, 0ah, 0   prompt3     byte "calculating choice ", 0ah, 0ah, 0  prompt4     byte "number of characters: ",0  prompt5     byte "number of words: ",0 prompt6     byte "number of sentences: ",0  prompt7     byte "number of letters equal 'n' or 'n': ",0  prompt8     byte "number of capital letters: ",0  prompt9     byte "number of vowels: ",0   sentinel    byte '$' thirdletter byte 'n' , 'n' space       byte ' '  num_char    dword ? num_words   dword ? num_sentences   dword ? num_thirdletter dword ? num_capletter   dword ? num_vowels  dword ?  .code main proc call mainmenu  exit main endp  mainmenu proc mov edx, offset mainmenu1 call writestring mov eax, 0; call readchar cmp al, '1' jne jumplabel1 call option1  jumplabel1: cmp al, '2' jne jumplabel2 call option2  jumplabel2: cmp al, '3' jne jumplabel3 call option3  jumplabel3: cmp al, '4' jne jumplabel4 call option4  jumplabel4: cmp al, '5' jne jumplabel5 call option5  jumplabel5: cmp al, '6' call option6 exit  mainmenu endp  option1 proc mov edx, offset prompt1 call writestring mov eax, 0 mov num_char, 1 mov num_words, 1 mov num_sentences, 1 mov num_thirdletter, 1 mov num_capletter, 1 mov num_vowels, 1  l1: call readchar call writetempoutput  cmp al, sentinel jne not_sentinel_flag mov edx, offset prompt2 call writestring jmp end_flag not_sentinel_flag: cmp al, space jne not_new_char_flag inc num_char  not_new_char_flag: cmp al, 0dh jne not_new_line_flag inc num_char not_new_line_flag: jmp l1; end_flag: call display_char_results option1 endp   option2 proc mov edx, offset prompt1 call writestring mov num_words, 1 mov num_sentences, 1 mov num_thirdletter, 1 mov num_capletter, 1 mov num_vowels, 1  l1: call readchar call writetempoutput cmp al, sentinel jne not_sentinel_flag mov edx, offset prompt2 call writestring jmp end_flag not_sentinel_flag: cmp al, space jne not_new_word_flag inc num_words not_new_word_flag: cmp al, 0dh jne not_new_line_flag inc num_words not_new_line_flag: jmp l1; end_flag: call display_word_results option2 endp  option3 proc mov edx, offset prompt1 call writestring mov num_capletter, 1 mov num_char, 1 mov num_sentences, 1 mov num_thirdletter, 1 mov num_vowels, 1 mov num_words, 1  l1: call readchar call writetempoutput cmp al, sentinel jne not_sentinel_flag mov edx, offset prompt2 call writestring jmp end_flag not_sentinel_flag: cmp al, 0dh jne not_new_line_flag inc num_sentences not_new_line_flag: jmp l1; end_flag: call display_sentences_results option3 endp  option4 proc mov edx, offset prompt1 call writestring mov num_capletter, 1 mov num_char, 1 mov num_sentences, 1 mov num_thirdletter, 1 mov num_vowels, 1 mov num_words, 1  l1: call readchar call writetempoutput cmp al, sentinel jne not_sentinel_flag mov edx, offset prompt2 call writestring jmp end_flag not_sentinel_flag: cmp al, 'n' jne not_uppercase_n inc num_thirdletter not_uppercase_n: cmp al, 'n' jne not_letter_n_flag inc num_thirdletter not_letter_n_flag: jmp l1; end_flag: call display_thirdletter_results option4 endp  option5 proc mov edx, offset prompt1 call writestring mov num_capletter, 1 mov num_char, 1 mov num_sentences, 1 mov num_thirdletter, 1 mov num_vowels, 1 mov num_words, 1  l1: call readchar call writetempoutput cmp al, sentinel jne not_sentinel_flag mov edx, offset prompt2 call writestring jmp end_flag  not_sentinel_flag: cmp al, 'a' - 'z' jbe not_capital_letter inc num_capletter not_capital_letter: jmp l1; end_flag: call display_capital_results option5 endp  option6 proc mov edx, offset prompt1 call writestring mov num_capletter, 1 mov num_char, 1 mov num_sentences, 1 mov num_thirdletter, 1 mov num_vowels, 1 mov num_words, 1  l1: call readchar call writetempoutput cmp al, sentinel  mov edx, offset prompt2 call writestring option6 endp          display_char_results proc mov edx, offset prompt3 call writestring mov edx, offset prompt4 call writestring mov eax, 0 mov eax, num_char call writedec call crlf call mainmenu display_char_results endp  display_word_results proc mov edx,offset prompt3 call writestring mov edx,offset prompt5 call writestring mov eax,0 mov eax,num_words call writedec call crlf call mainmenu display_word_results endp  display_sentences_results proc mov edx,offset prompt3 call writestring mov edx,offset prompt6 call writestring mov eax,0 mov eax,num_sentences call writedec call crlf call mainmenu display_sentences_results endp  display_thirdletter_results proc mov edx,offset prompt3 call writestring mov edx,offset prompt7           call writestring mov eax,0 mov eax,num_thirdletter call writedec call crlf call mainmenu display_thirdletter_results endp  display_capital_results proc mov edx, offset prompt3 call writestring mov edx, offset prompt8 call writestring mov eax, 0 mov eax, num_capletter call writedec call crlf call mainmenu display_capital_results endp  display_vowels_results proc mov edx, offset prompt3 call writestring mov edx, offset prompt9 call writestring mov eax, 0  mov eax, num_vowels call writedec call crlf call mainmenu display_vowels_results endp  writetempoutput proc cmp al,0dh           jne nonewline mov bl,al mov al,0ah           call writechar   mov al,bl call writechar ret nonewline: call dumpregs call writechar ret writetempoutput endp   exit end main 

your program has issues flow. when use call instruction expect return here. code screams jmp that's instruction should use correct problems.

cmp al, '1' jne jumplabel1 call option1   <-- change   jmp option1  jumplabel1: 

every time have block of code previous should not call rather jump relevant option_ procedure.

... l1: call readchar call writetempoutput  cmp al, sentinel jne not_sentinel_flag mov edx, offset prompt2 call writestring jmp end_flag not_sentinel_flag: cmp al, space jne not_new_char_flag inc num_char  not_new_char_flag: cmp al, 0dh jne not_new_line_flag      <-- change   je new_line_flag inc num_char not_new_line_flag:         <-- change   new_line_flag: jmp l1; end_flag: call display_char_results  <-- change   jmp display_char_results option1 endp  

in option1 procedure not counting characters! follow flow p.e. al=65 , you'll see num_char variable doesn't incremented. don't call display routine because programmed particular display routine not return here. jmp it.

display_char_results proc mov edx, offset prompt3 call writestring mov edx, offset prompt4 call writestring mov eax, 0             <-- can savely deleted mov eax, num_char call writedec call crlf call mainmenu          <-- change   jmp mainmenu display_char_results endp 

every display_..._results procedure should not call rather jump mainmenu label. way have got loop not rapidly filling stack , avoiding stack overflow.

jumplabel5: cmp al, '6' call option6 exit  mainmenu endp 

in code snippet don't outcome of compare. like

jumplabel5:  cmp al, '6'  jne badchoice  call option6       <-- remember change jump! badchoice:  exit  mainmenu endp 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -