斐波那契数列——汇编语言
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
datarea segment
string1 db 'please input the number: ',13,10,'$' string2 db 13,10,'here is:',13,10,'$'
Buffer db 4
db ?
db 4 dup(?)
number db ?
mulfact db 1
fei db 254 dup(?)
datarea ends
codearea segment
mainproc far
assume cs:codearea,ds:datarea
start:
push ds
sub ax,ax
push ax
mov ax,datarea
mov ds,ax
lea dx,string1
mov ah,09
int 21h
lea dx,Buffer
mov ah,0ah
int 21h
call convertnum
mov al,number
lea dx,string2
mov ah,09
int 21h
call init
; mov al,Buffer+1
; and ax,00ffh
; mov si,ax
call outputfei
; mov fei[si+1],24h
; lea dx,fei
; mov ah,09
; int 21h
ret
mainendp
;======================================= convertnum proc near
push bx
mov si,Buffer[1]
and si,00ffh
mov cx,si
mov mulfact,1
mov bx,0
Next:
mov al,Buffer[si+1]
; cmp al,'0'
; js Exit
; cmp al,'9'
; ja Exit
sub al,30h
and ax,000fh
mov dl,mulfact
mul dl
add bx,ax
mov al,mulfact
mov dl,10
mul dl
mov mulfact,ax
dec si
loop Next
mov number,bl
pop bx
ret
convertnum endp
;================================== init proc near
mov cx,al
and cx,00ffh
and ax,00ffh
mov si,1
; and si,00ffh
mov fei+1,1
mov fei+2,1
loop1:
sub cx,2
cmp si,cx
jnb exit
mov bl,0
add bl,fei[si]
add bl,fei[si+1]
mov fei[si+2],bl
inc si
jmp loop1
exit:
ret
init endp
;================================== outputfei proc near
mov cl,number
and cx,00ffh
mov si,0
loop4:
cmp si,cx
jz break
mov ax,fei[si+1]
and ax,00ffh
call output
inc si
jmp loop4
break:
ret
outputfei endp
;================================ output proc near
push ax
push bx
push cx
push dx
cmp ax,100
jl g2
mov bl,100
div bl
add al,30h
mov bh,ah
mov dl,al
mov ah,2
int 21h
mov al,bh
cbw
g2:
cmp ax,10
jl g4
mov bl,10
div bl
mov bh,ah
add al,30h
mov dl,al
mov ah,2
int 21h
mov al,bh
cbw
g4:
add al,30h
mov dl,al
mov ah,2
int 21h
mov dl,20h
mov ah,2
int 21h
pop dx
pop cx
pop bx
pop ax
ret
output endp codearea ends
end start