title: Assembly Language program stuck in an infinite loop
body: <p>My program seems to be stuck in a loop after the program prompts the user to input the paragraph.</p>
  
  <pre><code>TITLE CSC221A4  (CSC2214.asm)
  
  INCLUDE Irvine32.inc
  
  .data
  mainMenu1   BYTE    " ", 0Ah, 0Ah, 0Ah
              BYTE    "       Main Menu           ", 0Ah
              BYTE    " 1. Count and Display number of characters (Press 1)   ", 0Ah, 0Ah
              BYTE    " 2. Count and display number of words (Press 2) ", 0Ah, 0Ah
              BYTE    " 3. Count and display number of sentences (Press 3) ", 0Ah, 0Ah
              BYTE    " 4. Count and display numbers of letters that are equal to 'N' or 'n'  (Press 4)", 0Ah, 0Ah
              BYTE    " 5. Count and display number of capital letters (Press 5) ", 0Ah, 0Ah
              BYTE    " 6. Count and display number of vowels (Press 6) ", 0Ah, 0Ah
  
  prompt1     BYTE " ", 0Ah, 0Ah
              BYTE "Please enter your paragraph. Press $ to end.",0Ah, 0Ah, 0
  prompt2     BYTE " ", 0Ah, 0Ah
              BYTE " '$' was entered. Paragraph will now 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 to '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
  </code></pre>