汇编输出斐波那契数列
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
STACK SEGMENT STACK 'STACK'
DW 100H DUP(?)
TOP LABEL WORD
STACK ENDS
DATA SEGMENT
BUFFER DW 10H DUP(0)
STRING1 DB 'NAME:HanLei NO:12041719 NAME:WuTingwei NO:12041705$'
STRING2 DB 'INPUT NUMBER:$'
STRING3 DB 'Fibonacci Sequence :$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
DISPMESSAGE MACRO MESSGE
PUSH AX
PUSH DX
LEA DX,MESSGE
MOV AH,09H
INT 21H
POP AX
POP DX
ENDM
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV AX,STACK
MOV SS,AX
LEA SP,TOP
DISPMESSAGE STRING2
CALL READ
LEA SI,BUFFER
MOV [SI],AX
MOV CX,BUFFER
CALL HH
DISPMESSAGE STRING3
MOV BX,0H
MOV AX,1H
MOV DX,0H
DISP:
PUSH BX
ADD AX,BX
PUSH DX
CALL DISPAL
CALL DISPAL1
POP DX
POP BX
MOV BX,DX
MOV DX,AX
LOOP DISP
CALL HH
DISPMESSAGE STRING1
MOV AH,4CH
INT 21H
DISPAL PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH DI
MOV BX,10
MOV CX,5
CALL PD
TRANS1:
XOR DX,DX
DIV BX
MOV [DI],DL
PUSH DX
INC DI
LOOP TRANS1
MOV CX,5
TRANS2:
POP DX
PUSH AX
MOV AX,DX
CALL CHANG
MOV AH,02
MOV DL,AL
INT 21H
POP AX
LOOP TRANS2
POP DI
POP DX
POP CX
POP BX
POP AX
RET
DISPAL ENDP
CHANG PROC NEAR
CMP AL,10
JNGE CHANG1
ADD AL,7
CHANG1:
ADD AL,30H
RET
CHANG ENDP
PD PROC NEAR
CMP AX,0
JGE JUDGE1
PUSH AX
PUSH DX
MOV AH,02H
MOV AL,45
MOV DL,AL
INT 21H
POP DX
POP AX
NEG AX
JUDGE1:
RET
PD ENDP
DISPAL1 PROC NEAR
PUSH AX
PUSH DX
MOV AL,32
MOV AH,02
MOV DL,AL
INT 21H
POP DX
POP AX
RET
DISPAL1 ENDP
READ PROC NEAR
PUSH CX
PUSH DX
MOV CX,10
MOV BL,0
MOV AH,01H
INT 21H
CMP AL,'-'
JNZ READ1
JMP READ3
READ1:
MOV AH,10
SUB AL,30H
XCHG AL,BL
MUL AH
ADD BL,AL
READ2:
MOV AH,01H
INT 21H
CMP AL,30H
JB READ5
CMP AL,39H
JA READ5
MOV AH,10
SUB AL,30H
XCHG AL,BL
MUL AH
ADD BL,AL
LOOP READ2
READ3:
MOV AH,01H
INT 21H
CMP A
L,30H
JB READ4
CMP AL,39H
JA READ4
MOV AH,10
SUB AL,30H
XCHG AL,BL
MUL AH
ADD BL,AL
LOOP READ3
READ4:
NEG BL
READ5:
POP DX
POP CX
MOV AX,BX
RET
READ ENDP
HH PROC NEAR
MOV AH,02
MOV AL,13
MOV DL,AL
INT 21H
MOV AH,02
MOV AL,10
MOV DL,AL
INT 21H
RET
HH ENDP
CODE ENDS
END START