title: Assembly language program to display letters in an alphabet in pyramid based on user's input
body: <p>I am writing an assembly program to display letters in alphabet in pyramid based on the user's input. Example, if the user input letter a, the output would be:
  a
  ab
  abc
  .
  .
  .
  abcdef...z</p>
  
  <p>and if the user enters letter b, this would be the output:</p>
  
  <p>b
  bc
  bcd
  bcde
  .
  .
  .
  bcdefg...z</p>
  
  <p>and so on...</p>
  
  <p>below is my code and i'm really having problem about iterations, loops, nested loops, etc. i've been trying but to no avail. i am new to assembly language so my codes really sucks.</p>
  
  <pre><code>title print_alphabets
  
  ststack segment para stack 'stack'
          dw 200h
  ststack ends
  
  cdata segment para 'data'
          inputMessage db 'Enter a letter to start from: $'
          invalidInput db 10, 13, 'You have entered an invalid character. Please run the program again.$'
          newline db 10, 13, '$'
  cdata ends
  
  ccode segment para 'code'
          assume cs: ccode, ss: ststack, ds: cdata
  
      main:   
          mov ax, cdata
              mov ds, ax
  
          mov ah, 09h
              lea dx, inputMessage
              int 21h
  
              mov ah, 01h
              int 21h
  
          mov bl, al
  
          mov ch, 26
  
          mov cl, 26
  
      testinput:
          cmp bl, 7ah
          jbe loop1
  
          jmp invalid
  
      loop1:
          mov ah, 09h
              lea dx, newline
              int 21h 
  
          mov ah, 02h
              mov dl, bl
              int 21h
  
          dec ch
  
          cmp ch, 25
          je loop1
  
          cmp ch, 24
          jle loop2
  
          jmp endprog
  
          loop2:
              inc dl
  
              mov ah, 02h
                  mov dl, dl
                  int 21h
  
              dec cl
  
              cmp cl, 25
              je loop1
                  ;repeat loop2 once
                  cmp cl, 24
                  je loop2
  
              cmp cl, 23
              je loop1
                  ;repeat loop2 twice
                  cmp cl, 22
                  je loop2
  
                  cmp cl, 21
                  je loop2
  
              cmp cl, 20
              je loop1
                  ;repeat loop2 thrice
                  cmp cl, 19
                  je loop2
  
                  cmp cl, 18
                  je loop2
  
                  cmp cl, 17
                  je loop2
  
              cmp cl, 16
              je loop1
                  ;repeat loop2 4 times
                  cmp cl, 15
                  je loop2
  
                  cmp cl, 14
                  je loop2
  
                  cmp cl, 13
                  je loop2
  
                  cmp cl, 12
                  je loop2
  
              cmp cl, 11
              je loop1
                  ;repeat loop2 5 times
                  cmp cl, 10
                  je loop2
  
                  cmp cl, 9
                  je loop2
  
                  cmp cl, 8
                  je loop2
  
                  cmp cl, 7
                  je loop2
  
                  cmp cl, 6
                  je loop2
  
              jmp endprog
  
      invalid:
          mov ah, 09h
          lea dx, invalidInput
          int 21h
  
          jmp endprog
  
      endprog:
          mov ah, 4ch
          int 21h
  ccode ends
  end main
  </code></pre>