0

嘿伙计们,我不确定我是否以正确的方式进行这一切。我需要斐波那契数列的前 12 个数字来计算我已经很确定它在做什么。但是现在我需要使用 dumpMem 在我的程序中显示 (Fibonacci) 的十六进制内容。我需要打印:01 01 02 03 05 08 0D 15 22 37 59 90

但我只得到:01 01 00 00 00 00 00 00 00 00 00 00

非常感谢任何提示或帮助。

 INCLUDE Irvine32.inc
.data

reg DWORD -1,1,0                    ; Initializes a DOUBLEWORD array, giving it the values of -1, 1, and 0
array DWORD 48 DUP(?)
Fibonacci BYTE 1, 1, 10 DUP (?) 



.code
main PROC
       mov array, 1
       mov esi,OFFSET array ; or should this be Fibonacci?
       mov ecx,12
       add esi, 4


    L1:
        mov edx, [reg]
        mov ebx, [reg+4]
        mov [reg+8], edx
        add [reg+8], ebx                    ; Adds the value of the EBX and 'temp(8)' together and stores it as temp(8) 
        mov eax, [reg+8]                    ; Moves the value of 'temp(8)' into the EAX register        
        mov [esi], eax                      ; Moves the value of EAX into the offset of array
        mov [reg], ebx                      ; Moves the value of the EBX register to 'temp(0)' 
        mov [reg+4], eax                    ; Moves the value of the EAX register to 'temp(4)
        add esi, 4

       ; call DumpRegs
        call WriteInt
        loop L1

        ;mov ebx, offset array
        ;mov ecx, 12

        ;L2: 
        ;mov eax, [esi]
        ;add esi, 4
        ;call WriteInt
        ;loop L2

  ;Below will show hexadecimal contents of string target-----------------
   mov   esi, OFFSET Fibonacci      ; offset the variables
   mov   ebx,1                      ; byte format
   mov   ecx, SIZEOF Fibonacci      ; counter
   call  dumpMem 


exit
main ENDP

END main
4

2 回答 2

2

您对 dumpMem 的调用是正确的,但您的程序没有将计算结果存储在正确的位置:您调用“斐波那契”的区域仍然初始化为 1、1 和 10 个零。您需要确保您的循环从 Fibonacci 的偏移量加 2 开始写入,并以一个字节为增量移动十次(十次,而不是十二次,因为您在初始化程序中提供了两个初始项)。

对不起,我不能再具体了,因为任何包含“斐波那契”这个词的问题都不可避免地会成为某人的作业:-)

于 2011-11-28T21:51:23.243 回答
2

It seems to me that the problem here is with computing the Fibonacci sequence. Your code for that leaves me somewhat...puzzled. You have a bunch of "stuff" there, that seems to have nothing to do with computing Fibonacci numbers (e.g., reg), and others that could, but it seems you don't really know what you're trying to do with them.

Looking at your loop to compute the sequence, the first thing that practically jumps out at me is that you're using memory a lot. One of the first (and most important) things when you're writing assembly language is to maximize your use of registers and minimize your use of memory.

As a hint, I think if you read anything from memory in the course if computing the sequence, you're probably making a mistake. You should be able to do all the computation in registers, so the only memory references will be writing results. Since you're (apparently) producing only byte-sized results, you should need only one array of the proper number of bytes to hold the results (i.e., one byte per number you're going to generate).

I'm tempted to write a little routine showing how neatly this can be adapted to assembly language, but I suppose I probably shouldn't do that...

于 2011-11-28T21:51:44.023 回答