Advertisement
Masum6035

For Foysal

Apr 26th, 2021
2,943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Problem-1-solution     id-201914044
  2. .model small   
  3. .stack 100h    
  4. include 'emu8086.inc'
  5.  
  6. .data
  7.  
  8. n_line db 0ah,0dh,"$"   ;for new line  
  9. msg1 db "input : $"
  10. msg2 db 10,13,"output : $"
  11. num db ?
  12. count db ?
  13.  
  14. .code
  15.  
  16. main proc
  17.     mov ax,@data   
  18.     mov ds,ax    
  19.    
  20.     lea dx,msg1
  21.     mov ah,9
  22.     int 21h
  23.    
  24.     mov ah,1
  25.     int 21h
  26.     sub al,48  
  27.     mov num,al
  28.    
  29.     xor bx,bx    
  30.     xor dx,dx
  31. @input:  
  32.     add dx,bx
  33.     cmp num,0
  34.     je @next_step
  35.                
  36.     mov al,num
  37.     mul num
  38.     mul num
  39.    
  40.     mov bx,ax    
  41.     dec num
  42.     jmp @input
  43.    
  44. @next_step:  
  45.     mov bx,dx     ;my result is stored in dx so i'm moving it
  46.    
  47.     lea dx,msg2
  48.     mov ah,9
  49.     int 21h
  50.    
  51.     mov ax,bx
  52.     mov count,0
  53.     mov dx,0    
  54.     xor bx,bx
  55.     @output:
  56.         cmp ax,0
  57.         je @inside_output      
  58.          
  59.         mov bx,10          
  60.         div bx                  
  61.         push dx              
  62.  
  63.         inc count              
  64.         xor dx,dx   ;clearing dx register for my next loop
  65.         jmp @output  
  66.        
  67.     @inside_output:
  68.         cmp count,0
  69.         je @stop
  70.  
  71.         pop dx
  72.         add dx,48
  73.  
  74.         mov ah,02h
  75.         int 21h
  76.  
  77.         dec count
  78.         jmp @inside_output
  79. @stop:    
  80.     mov ah,4ch
  81.     int 21h         ;terminate with return code
  82. main endp
  83.    
  84. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement