2016-12-10 8 views
-2

내 코드는 사용자가 지정한 숫자를 기반으로 피보나치 시리즈의 요소를 생성하는 것입니다. 내가 입력 한 숫자가있을 때마다 출력하는 것 외에는 무한 루프가됩니다. 아니. 여기에 입력 내가 요소 .. 그리고 내가 피보나치 시퀀스를 인쇄하는 데 사용하는 절차입니다 : 필요한 경우 내 완벽하게 작성된 코드 내가 EMU8086 asm8086에서 피보나치 시리즈를 생성하는 동안 무한 루프

  • here을 사용하고

    displayFib proc 
    MOV DX, 30h   ; move value 30 hexadecimal to DX, which represents 0 
    call display 
    MOV AX, input 
    CMP AX, 0  ;if the input is 0 in hexadecimal ASCII value then jump to finish 
    JE finish_it 
    
    mov ah,9    ; formating - coma 
    mov dx,offset msg3 
    int 21h  
    
    ;display the 1st term 
    MOV DX, 31h   ; move value 31 hexadecimal to DX, which represents 1 
    call display 
    CMP input, 1  ;if the input is 1 in hexadecimal ASCII value then jump to finish 
    JE finish_it 
    
    MOV CX, input  ;intializing counter, knowing that first 2 terms were displayed already 
    SUB CX, 2 
    
    repeat: 
        mov ah,9    ; formating - coma 
        mov dx,offset msg3 
        int 21h  
    
        MOV AX, fibn_2  ; calculating the n'th term of a sequence n = (n-1) + (n-2) 
        ADD AX, fibn_1 
        MOV fib, AX 
        MOV DX, fib 
        MOV saveCount, CX  ;saving the state of the counter as it will be modified in the displayNum 
        call displayNum 
        ;display the n'th term (current term) 
        MOV CX, saveCount  ;restoring state of the counter 
        MOV AX, fibn_1  ; n-1 in the next round of a loop will be n-2 
        MOV fibn_2, AX 
        MOV AX, fib   ;n'th term in the next round will be n-1 
        MOV fibn_1, AX 
        DEC CX    ;decrementing counter 
        JNZ repeat   ; loop until counter = 0 
    
    finish_it: 
    
    ret 
    displayFib endp 
    
    • 입니다

    감사합니다,

  • +1

    에뮬레이터를 사용하여 코드를 단계별로 실행하지 않았습니까? – Jester

    +0

    그래,하지만 난 아직 어디 초보자이며 그게 거의 내 첫 코드는 오류가 어디 있는지 찾을 수 없습니다 .. –

    답변

    1
    MOV CX, input  ;intializing counter, knowing that first 2 terms were displayed already 
    SUB CX, 2 
    

    입력이 2 일 때 어떻게됩니까? 무한 루프 !!!


    올바른 방법으로 입력을 처리하지 않으므로 프로그램이 실패합니다!

    KEYIN 루틴은 AH 레지스터를 파괴, 아직 당신은 NUM1 변수에 AX 레지스터를 이동합니다. 명시 적으로 AH 레지스터를 제로로 수정하십시오.

    call keyin  ;gets user input 
    SUB AL, 48  ;changes ASCII value into numeric value for further processing 
    
    mov ah, 0  <<<<<<< ADD THIS 
    
    mov num1 , AX ;saves user input to variable num1 
    

    동일한 것이 NUM2 변수 간다.

    /터지는를 밀어 일어난 무엇이든
    MOV saveCount, CX  ;saving the state of the counter as it will be modified in the displayNum 
    call displayNum   ;display the n'th term (current term) 
    MOV CX, saveCount  ;restoring state of the counter 
    

    ?

    PUSH CX    ;saving the state of the counter as it will be modified in the displayNum 
    call displayNum  ;display the n'th term (current term) 
    POP CX    ;restoring state of the counter 
    
    +0

    당신의 상세한 솔루션을 많이 고마워 :) :)하지만 불행히도 나는 여전히 같은 문제가 있습니다 .. –

    +0

    고마워요. .. 지금 작동 :) :)))))) –