Advertisement
tsnaik

MFP lab7

Aug 23rd, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Fibonacci (passing through register)
  2.  
  3. data segment
  4.  
  5.         m db 08
  6.         ans dw ?
  7.         n1 db 01
  8.         n2 db 01
  9.  
  10. data ends
  11.  
  12. mystack segment
  13.  
  14.     dw 100 dup(0)
  15.     TOS Label word
  16.  
  17. mystack ends
  18.  
  19. code segment
  20.  
  21.     assume cs:code,ds:data,ss:mystack
  22.  
  23.         mov ax,data
  24.         mov ds,ax
  25.         xor ax,ax
  26.        
  27.         mov ax,mystack
  28.         mov ss,ax
  29.         lea sp,TOS
  30.         xor ax,ax
  31.     call fibo
  32.     mov ax,ans
  33.     int 03H
  34.    
  35.    
  36. fibo proc near        
  37.         PUSHF
  38.         mov al,02
  39.         cmp al,m
  40.         jnc next
  41.         mov cl,m
  42.         dec cl
  43.         dec cl
  44.        mov al,0
  45.           mov bl,1
  46.        p:
  47.           add al,bl
  48.           mov dl,al
  49.           mov al,bl
  50.           mov bl,dl
  51.           LOOP p
  52.           mov byte ptr[ans],dl
  53.           jmp q
  54.        next :
  55.            mov bl,01
  56.            cmp bl,m
  57.            jz first
  58.            
  59.            mov ans,01
  60.            jmp q
  61.          first:  
  62.             mov ans,0
  63.          
  64.          q: POPF
  65.             ret
  66.            
  67.    fibo endp
  68.  code ends
  69.  end
  70.  
  71.  
  72.  
  73. ;reverse string(passing through pointers)
  74. data segment
  75.  str1 db 'hello'
  76.  b dw ($-str1)
  77.  str2 db 10 dup(0)
  78. data ends
  79.  
  80. s_seg segment
  81.  dw 100 dup(0)
  82.  tos label WORD
  83. s_seg ends
  84.  
  85. code segment
  86.  assume cs:code,ds:data,ss:s_seg
  87.  mov ax,data
  88.  mov ds,ax
  89.  xor ax,ax
  90.  mov ax,s_seg
  91.  mov ss,ax
  92.  lea sp,tos
  93.  lea si,str1
  94.  add si,b
  95.  lea di,str2
  96.  call reverse
  97.  int 3
  98.  
  99. reverse proc near
  100. pushf
  101. mov cx,b
  102. inc cx
  103. x1: mov al,byte ptr[si]
  104.     mov byte ptr[di],al
  105.     dec si
  106.     inc di
  107.     loop x1
  108.    
  109.   popf
  110.   ret
  111.   reverse endp
  112.   code ends
  113.   end
  114.  
  115.  
  116. NOTE:
  117. ;even if we are not initializing stack segment, we can call the procedure. It's not compulsory to initialize the stack segment.
  118. ;we can use base pointer as an offset inside procedure.
  119. ;we can also use push and pop as many as we want in main line code.
  120.  
  121. ;some program 3: factorial (passing by stack)
  122.  
  123. ;assignment: given a decimal number, implement a procedure to find out whether it is armstrong number or not. Pass the value by stack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement