; lab3 use proc(parameter passing by stack)
; to calculate the sum of the first n terms of the Fibonacci series
.model small
.data
n equ 3
.code
push n
call fib
.exit 0
fib proc
; stack top : return ip
; stack top -1 : n
; output ax: sum of n size fib
pop di ; hold return ip
pop cx ; n
; if n == 1
cmp cx, 1
jnz elif
mov ax, 1
push di ; resitution return ip
ret
; elif n == 2
elif:
cmp cx, 2
jnz else
mov ax, 1
push di ;resitution return ip
ret
; else
else:
; call fib n-1
dec cx
push cx ; n-1
call fib
mov dx, ax ; temp store fib n-1
; call fib n-2
dec cx
push cx ; n-2
call fib
add ax, dx ; cal fib n-1 + fib n-2
push di ; resitution return ip
ret
fib endp
end
09-19
1万+
01-16
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交