首页 > 解决方案 > 装配中大量斐波那契的问题

问题描述

我的代码低于代码工作,但是对于超过 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
;***************************************************************        

标签: assembly

解决方案


您将所有内容存储为单个字节,因此当值超过 255 时,它会失败。


推荐阅读