?? fibona.asm
字號:
data segment
message1 db 'N=?',0ah,0dh,'$'
message2 db 'F(',?,?,?,?,'H)='
char_res db 0,0,0,0,'H',0ah,0dh,'$'
N dw 0
count dw 0
data ends
;...........................................
code segment
main proc far
assume cs:code,ds:data
start:
;set up stack for return
push ds;
sub ax, ax
push ax
;set ds register to current data segment
mov ax, data
mov ds, ax
lea dx, message1 ;N=?
mov ah, 09h
int 21h
call decibin ;read N into BX
call crlf ;print a line
cmp N, 100 ;if N>100
jns exit
mov cx, N
lop:
push cx
mov count, cx
call fib ;call fin(N)
pop cx
call binihex ;
lea dx, message2
mov ah, 09h
int 21h
loop lop
exit:
ret
main endp
;...........................................
decibin proc near
;procedure to convert decimal on keybd to binary
;result is left in BX register.
mov bx, 0 ;clear BX for number
;get digit from keyboard, convert to binary
newchar:
mov ah, 1 ;keyboard input
int 21h ;call DOS
sub al, 30h ;ASCII to binary
jl exit_dec ;jump if<0
cmp al, 9d ;is it <9?
jg exit_dec ;yes,not dec digit
cbw ;byte in AL to word in AX
;(digit is now in Ax)
;multiply number in BX by 10 decimal
xchg ax, bx ;trade digit & number
mov cx, 10d ;put 10 dec in CX
mul cx ;number times 10
xchg ax, bx ;trade number & digit
;add digit in AX to number in BX
add bx, ax ;add digit to number
jmp newchar ;get next digit
exit_dec:
mov N, bx ;save the digit into N
ret ;return from decibin
decibin endp ;end of decibin proc
;...........................................
crlf proc near
mov dl, 0dh ;linefeed
mov ah, 02h ;display function
int 21h
mov dl, 0ah ;carriage return
mov ah, 02h ;display function
int 21h
ret
crlf endp
;...........................................
fib proc near
cmp cx, 01h ;if N=1,result=1,return
jz fib_end
cmp cx, 02h ;if N=2,result=1,return
jz fib_end
dec cx
push cx
call fib
pop cx
mov ax, bx ;temp1
push ax
dec cx
push cx
call fib
pop cx
mov dx, bx ;temp2
pop ax
add ax, dx
mov bx, ax ;bx=temp1+temp2
jmp fib_exit
fib_end:
mov bx, 1d
fib_exit:
ret
fib endp
;...........................................
;result is left in BX register
binihex proc near
push ax
push bx
push cx
push dx
push si
mov ch, 4 ;4 times
mov cl, 4 ;move 4 bit
sub ax, ax ;move zero into ax
sub si, si ;clear si
rotate1:
rol bx, cl
mov dl, bl
and dl, 0fh
add dl, 30h
cmp dl, 3ah
jl tochar1
add dl, 07h
tochar1:
mov char_res[si], dl ;move result into char_res for show
inc si
dec ch
jnz rotate1
mov bx, count
mov ch, 4 ;4 times
mov cl, 4 ;move 4 bit
sub ax, ax ;move zero into ax
sub si, si ;clear si
add si, 2
rotate2:
rol bx, cl
mov dl, bl
and dl, 0fh
add dl, 30h
cmp dl, 3ah
jl tochar2
add dl, 07h
tochar2:
mov message2[si], dl ;move result into char_res for show
inc si
dec ch
jnz rotate2
pop si
pop dx
pop cx
pop bx
pop ax
ret
binihex endp
code ends
end main
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -