Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 在x86 asm中显示前N个斐波那契数_Visual Studio_Assembly_X86_Fibonacci_Irvine32 - Fatal编程技术网

Visual studio 在x86 asm中显示前N个斐波那契数

Visual studio 在x86 asm中显示前N个斐波那契数,visual-studio,assembly,x86,fibonacci,irvine32,Visual Studio,Assembly,X86,Fibonacci,Irvine32,我想使用Irvine库在x86 asm中生成第一个N斐波那契数。这意味着每当我给出N=5时,它应该打印:0,1,1,2,3,但是每当我用N=5运行它时,它就会给出输出:0,1,2,3,4 下面是我的程序 TITLE MASM Irvine INCLUDE Irvine32.inc .data message1 BYTE "The first ",0 message2 BYTE " numbers in the Fibonacci sequence a

我想使用Irvine库在x86 asm中生成第一个N斐波那契数。这意味着每当我给出N=5时,它应该打印:0,1,1,2,3,但是每当我用N=5运行它时,它就会给出输出:0,1,2,3,4

下面是我的程序

TITLE MASM Irvine
INCLUDE Irvine32.inc
.data
    message1 BYTE "The first ",0
    message2 BYTE " numbers in the Fibonacci sequence are the following.",0
    N DWORD 10
    intialVal WORD 0,1

.code
main PROC

    call Clrscr ; clears screen

    mov edx,OFFSET message1
    call WriteString            ; display message1
    mov eax, N
    call WriteDec               ; display num
    mov edx,OFFSET message2
    call WriteString            ; display message2
    call Crlf                   ; new line

    mov eax,0
    mov bx, [intialVal]
    mov cx, [intialVal + 2]
StartLoop:
    mov edx,0       ;setting edx to 0 every time
    add dx,bx       ;adding bx to dx
    add dx,cx       ;adding cx to dx
    call WriteDec   
    call Crlf       ;trying to print dx
    mov bx,cx       ;moving numbers. so now cx goes to bx
    mov cx,dx       ;dx goes to cx 
    inc eax         ;increment eax (as a counter)
    cmp eax,N       ;compare to variable N
    jne StartLoop   ;if eax = N exit loop, else jump to start of loop

    exit
main ENDP
END main

WriteDec
获取要在
eax
中打印的号码,而不是
edx
。所以你正在打印计数器。PS:你为什么要使用16位寄存器?那么我需要把内容放在
eax
寄存器中吗?没有理由,我是大学里的一名Sophore教授,我们的课程刚刚结束,所以我一直在努力研究我的所有东西own@Jester非常感谢。那句话就是我所需要的,我想明白了。非常感谢:D