Advertisement
Andziev

recursiveProcedure assembly

Nov 14th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; multi-segment executable file template.
  2.  
  3. data segment
  4.     ; add your data here!
  5.     N db ?
  6.     suma db 0
  7.     first db 1
  8.     returnInst dw ?
  9. ends
  10.  
  11. stack segment
  12.     dw   128  dup(0)
  13. ends
  14.  
  15. code segment
  16. sum proc  
  17.     cmp first, 1d
  18.     je firstTime    
  19.    
  20.     cmp cl, 01d
  21.     je end
  22.    
  23.     mov al, cl
  24.     mov ah, 0d
  25.     mov dl, 3d
  26.     div dl
  27.  
  28.     cmp ah, 0d
  29.     jne calling
  30.    
  31.     add bl, cl    
  32.    
  33.     calling:
  34.         dec cx        
  35.         call sum        
  36.     end:
  37.         push bx
  38.         push returnInst
  39.         ret
  40.        
  41.     firstTime:
  42.         pop returnInst
  43.         pop cx
  44.         mov al, 0d    
  45.         mov first, 0d
  46.         call sum
  47. sum endp
  48. start:
  49. ; set segment registers:
  50.     mov ax, data
  51.     mov ds, ax
  52.     mov es, ax
  53.  
  54.     mov ah, 01h
  55.     int 21h
  56.     sub al, 48d
  57.     mov ah, 0d
  58.     mov dl, 10d
  59.     mul dl
  60.     mov N, al
  61.    
  62.     mov ah, 01h
  63.     int 21h
  64.     sub al, 48d
  65.     add N, al
  66.    
  67.     mov cl, N
  68.     mov ch, 0d
  69.     push cx
  70.    
  71.     call sum
  72.    
  73.     pop ax
  74.     mov sum, al
  75.            
  76.     mov ax, 4c00h ; exit to operating system.
  77.     int 21h    
  78. ends
  79.  
  80. end start ; set entry point and stop the assembler.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement