assembly - 装配中大量斐波那契的问题
问题描述
我的代码低于代码工作,但是对于超过 233 的数字(作为斐波那契数),当我打印它们时,答案是错误的。为什么?数字 1,1,2,3,5,8,...,233 是可以的,但在 233 之后数字是错误的
.model small
.stack 64
.data
B db ?
C db ?
D dw ?
Array DB 20 DUP(0), '$'
Array_2 DB 8 DUP(0), '$'
print_1 DB 13,10,"Please Enter A Number : 0< Number <13 --- And After 2 Digit Input '+' : Examlpe : 11+ :",13,10,"$"
print_2 DB 13,10,"Fibonacci Series : $"
Print_3 DB " $"
.code
;****************************************************************
main proc far
mov ax,@data
mov ds,ax
call RequestP ;
call Input ;
call Process ;Callings
call AnswerP ;
call Output ;
mov ax,4c00h
int 21h
;*********************************************************
main endp
RequestP proc near
mov AH, 9
lea DX, print_1 ;Printing the
requestP
int 21h
ret
RequestP endp
;*********************************************************
Input proc near
mov ax,0
MyLoop0:
mov ah,01
int 21h
cmp al,'+'
je GoOut
sub al,30h ;Getting Users Number
add B,al
mov al,B
mov ah,10
mul ah
mov B,al
jmp MyLoop0
GoOut:
mov bl,10
mov al,B
mov ah,0
div bl
mov B,al
inc B
ret
Input endp
;*********************************************************
Process proc near
mov cl,B
lea si,Array+1
mov [si-1],1 ;Defining the Array
mov [si],1
MyLoop:
mov [si+1],0
mov bx,[si-1]
mov dx,[si]
mov bh,0
add bx,dx ;Processing Code&Putting in the Array
mov [si+1],bx
inc si
dec cl
cmp cl,0
jne MyLoop
ret
Process endp
;*********************************************************
AnswerP proc near
mov AH, 9
lea DX, print_2 ;Printing the answerP
int 21h
ret
AnswerP endp
;*********************************************************
Output proc near
mov cl,B
lea si,Array
MyLoop2:
call PrintSpace
call GetDigit ;Printing Digits
inc si
dec cl
cmp cl,0
jne MyLoop2
ret
Output endp
;*********************************************************
GetDigit proc near
mov di,0
MyLoop3:
mov ax,[si]
mov ah,0
mov bl,10
div bl
add ah,30H ;Printing Digits Proccess
mov Array+di,ah
inc di
mov [si],al
cmp al,0
jne MyLoop3
MyLoop4:
dec di
mov dl,Array+di
mov ah,02 ;Reversing the Digits
int 21h
cmp di,0
jne MyLoop4
ret
GetDigit endp
;*********************************************************
PrintSpace proc near
mov AH, 9
lea DX, print_3 ;Printing Space
int 21h
ret
PrintSpace endp
end main
;***************************************************************
解决方案
您将所有内容存储为单个字节,因此当值超过 255 时,它会失败。
推荐阅读
- java - 在批处理文件中解析可执行控制台输出
- c# - 如何在 C# 中删除所有带括号的字符串?
- python - 在 Tkinter 中使用 Arduino 数据动态更新标签和实时图
- maven - 如何在不先编译的情况下运行 maven failsafe
- javascript - 您可以通过 JavaScript 或 php 将您在浏览器中所做的更改保存到本地 HTML 文件吗?
- excel - 根据文件夹名称中包含的日期返回最新的文件夹目录
- android - 如何从 GSON 中的 Json 数组中排除对象的反序列化?
- realm - Swift 4.0 和 Xcode 9.4 下的 RLMSupport.swift 编译错误
- cakephp - 如何使用 Cakephp 进行查询连接?
- javascript - 将水平滚动更改为垂直滚动