Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Fibonacci (passing through register)
- data segment
- m db 08
- ans dw ?
- n1 db 01
- n2 db 01
- data ends
- mystack segment
- dw 100 dup(0)
- TOS Label word
- mystack ends
- code segment
- assume cs:code,ds:data,ss:mystack
- mov ax,data
- mov ds,ax
- xor ax,ax
- mov ax,mystack
- mov ss,ax
- lea sp,TOS
- xor ax,ax
- call fibo
- mov ax,ans
- int 03H
- fibo proc near
- PUSHF
- mov al,02
- cmp al,m
- jnc next
- mov cl,m
- dec cl
- dec cl
- mov al,0
- mov bl,1
- p:
- add al,bl
- mov dl,al
- mov al,bl
- mov bl,dl
- LOOP p
- mov byte ptr[ans],dl
- jmp q
- next :
- mov bl,01
- cmp bl,m
- jz first
- mov ans,01
- jmp q
- first:
- mov ans,0
- q: POPF
- ret
- fibo endp
- code ends
- end
- ;reverse string(passing through pointers)
- data segment
- str1 db 'hello'
- b dw ($-str1)
- str2 db 10 dup(0)
- data ends
- s_seg segment
- dw 100 dup(0)
- tos label WORD
- s_seg ends
- code segment
- assume cs:code,ds:data,ss:s_seg
- mov ax,data
- mov ds,ax
- xor ax,ax
- mov ax,s_seg
- mov ss,ax
- lea sp,tos
- lea si,str1
- add si,b
- lea di,str2
- call reverse
- int 3
- reverse proc near
- pushf
- mov cx,b
- inc cx
- x1: mov al,byte ptr[si]
- mov byte ptr[di],al
- dec si
- inc di
- loop x1
- popf
- ret
- reverse endp
- code ends
- end
- NOTE:
- ;even if we are not initializing stack segment, we can call the procedure. It's not compulsory to initialize the stack segment.
- ;we can use base pointer as an offset inside procedure.
- ;we can also use push and pop as many as we want in main line code.
- ;some program 3: factorial (passing by stack)
- ;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