stack segment stack
db 512 dup(?)
stack ends
_BSS segment word public 'BSS'
b@ label byte
[email protected] label word
_BSS ends
_DATA segment word public 'DATA'
d@ label byte
[email protected] label word
input1 db "Please input the size of Fibonacci series(0~22):", 0ah, 0dh, '$'
input2 db " ", '$'
input3 db "The Fibonacci series you wanted is as following:", 0ah, 0dh, '$'
_maxn label word
dw 16191
_first_block label word
dw 0
_DATA ends
code segment
assume ds: _data, cs: code, ss: stack
main:
mov ax, _data
mov ds, ax
mov ax, stack
mov ss, ax
call _main
call lineFeed
jmp done
_main proc near
push bp
mov bp,sp
sub sp,6
push si
push di
xor si,si
mov di,1
lea dx, input1
mov ah, 09h
int 21h
call readsiw ;指定数列长度
mov word ptr [bp-4],ax
mov word ptr [bp-6],1
lea dx, input3
mov ah, 09h
int 21h
mov ax, word ptr [bp-6]
call dispsiw
lea dx, input2
mov ah, 09h
int 21h
jmp short @5
@4:
push si
mov ax,offset _DATA:d@
push ax
pop cx
pop cx
mov ax,si
add ax,di
mov word ptr [bp-2],ax
call dispsiw
lea dx, input2
mov ah, 09h
int 21h
mov si,di
mov di,word ptr [bp-2]
@3:
inc word ptr [bp-6]
@5:
mov ax,word ptr [bp-6]
cmp ax,word ptr [bp-4]
jle @4
@2:
xor ax,ax
jmp short @1
@1:
pop di
pop si
mov sp,bp
pop bp
ret
_main endp
readsiw proc
push bx
push cx
push dx
xor bx, bx
xor cx, cx
mov ah, 1
int 21h
cmp al, '+'
jz rsiw1
cmp al, '-'
jnz rsiw2
mov cx, -1
rsiw1:
mov ah, 1
int 21h
rsiw2:
cmp al, '0'
jb rsiw3
cmp al, '9'
ja rsiw3
sub al, 30h
xor ah, ah
shl bx, 1
mov dx, bx
shl bx, 1
shl bx, 1
add bx, dx
add bx, ax
jmp rsiw1
rsiw3:
cmp cx, 0
jz rsiw4
neg bx
rsiw4:
mov ax, bx
pop dx
pop cx
pop bx
ret
readsiw endp
dispsiw proc
push ax
push bx
push dx
test ax, ax
jnz dsiw1
mov dl, '0'
mov ah, 2
int 21h
jmp dsiw5
dsiw1:
jns dsiw2
mov bx, ax
mov dl, '-'
mov ah, 2
int 21h
mov ax, bx
neg ax
dsiw2:
mov bx, 10
push bx
dsiw3:
cmp ax, 0
jz dsiw4
xor dx, dx
div bx
add dl, 30h
push dx
jmp dsiw3
dsiw4:
pop dx
cmp dl, 10
je dsiw5
mov ah, 2
int 21h
jmp dsiw4
dsiw5:
pop dx
pop bx
pop ax
ret
dispsiw endp
lineFeed proc
push ax
push dx
mov dl, 0dh
mov ah, 2
int 21h
mov dl, 0ah
mov ah, 2
int 21h
pop dx
pop ax
ret
lineFeed endp
done:
mov ax, 4c00h
int 21h
code ends
end main