title: Print triangle of multidigit number in assembly x86
body: <p>I have to do o program which read a number between 0 and 255 and print a half pyramid, like this:</p>
  
  <pre><code>input: 4
  
  output:
  
  1
  1 2
  1 2 3
  1 2 3 4
  </code></pre>
  
  <p>I've managed to do it for numbers between 0 and 9, but i really can't do it for two or three digits numbers. </p>
  
  <p>See the following code </p>
  
  <pre><code>.model small
  .stack 100h
  
  .data
      msg db "Enter the desired value: $", 10, 13
      nr db ?
  
  .code
      mov AX, @data
      mov DS, AX
  
      mov dl, 10
      mov ah, 02h
      int 21h
      mov dl, 13
      mov ah, 02h
      int 21h
  
      mov DX, OFFSET msg
      mov AH, 9
      int 21h
      xor ax, ax
  
      mov ah, 08h                 
    int 21h
  
  
    mov ah, 02h   
    mov dl, al
    int 21h   
  
   sub al,30h  
    mov ah,10
    mul ah                
  
    mov [nr],al         
  
    mov ah, 08h 
    int 21h   
  
  
  
    mov ah, 02h         
    mov dl, al
    int 21h
  
    sub al, 30h         
    add [nr], al 
  
  
      sub nr,30h
  
      mov dl, 10
      mov ah, 02h
      int 21h
      mov dl, 13
      mov ah, 02h
      int 21h
  
      mov cx,1
  
      mov bx,31h
      mov ah, 2
      mov dx, bx
      int 21h 
  
  loop1:
      xor ax, ax
      mov al, nr
      cmp ax, cx
      je final
  
      mov dl, 10
      mov ah, 02h
      int 21h
      mov dl, 13
      mov ah, 02h
      int 21h
  
      mov bx, 0             
  
  loop2:  
      inc bx               
      add bx,30h
      call function
      int 21h 
      sub bx,30h
      cmp bx, cx           
      jne loop2
  
      inc bx               
      add bx,30h
      mov ah, 2
      mov dx, bx
      int 21h 
  
      inc cx
      jmp loop1
  
  
      function:   
  
  
      MOV BX,10 
  
  ASC2:
          mov dx,0            ; clear dx prior to dividing dx:ax by bx
          DIV BX              ;DIV AX/10
          ADD DX,48           ;ADD 48 TO REMAINDER TO GET ASCII CHARACTER OF NUMBER 
          dec si              ; store characters in reverse order
          mov [si],dl
          CMP AX,0            
          JZ EXTT             ;IF AX=0, END OF THE PROCEDURE
          JMP ASC2            ;ELSE REPEAT
  
  EXTT:
          mov ah,9            ; print string
          mov dx,si
          int 21h
  
  final:
      mov AH,4Ch   ; Function to exit
      mov AL,00    ; Return 00
      int 21h
  end
  </code></pre>