如何在此汇编代码中将输出中的字符串分成两部分

How do I break the string in output into 2 parts in this assembly code

所以我想将 break "The nth term in Fibonacci Series is " 字符串分成两部分:

"The " 和 "th term in Fibonacci Series is ",打印第一个字符串,然后打印 n 的值(比如使用 WriteInt),然后打印第二个字符串。

但我似乎无法获得正确的输出,关于如何将它们分成两部分的任何提示?

这是我现在的输出(假设我输入了 4 作为输入):

Display Fibonacci Series
Enter number of fibonacci series terms: 4
Fibonacci Series is
0
1
1
2
Sum of Fibnoacci Series = 4
Press any key to continue... 

如何将其更改为我想要的输入:

Display Fibonacci Series
Enter the number in fibonacci sequence number: 4
The 4th sequence in Fibonacci Series is
2
Press any key to continue... 

另外,现在这段代码中的公式是斐波那契数列,我该如何将其更改为这样的新公式;

f(n-2)/2 + f(n-1) * 2

这是我的代码:

INCLUDE Irvine32.inc

.DATA
; insert variables here
  dPrevious DWORD 0   
    dCurrent  DWORD 1   
    dNext DWORD 1     
    dNumberOfTerms DWORD 0
    dSum DWORD 0
    msg1 BYTE "Enter the Fibonacci sequence number : ",0 ; A null-terminated string
    msg2a BYTE "The ", 0
    msg2b BYTE "th term in Fibonacci Series is ", 0
    msg3 BYTE "th term in Fibonacci Series is ", WriteString
    msg4 BYTE "Error: Fibonacci Series must have at least 2 numbers",0



 .CODE
; insert all executable statements here
main PROC
    mov edx, OFFSET msgFibonacciSeries  ; "Display Fibonacci Series and Sum of Fibonacci Series in Assembly Language "
    call WriteString                    ; Display a null-terminated string.
    call Crlf                           ; Writes an end-of-line sequence to the console window.

    mov edx, OFFSET msg1      ; "Enter Number of Fibonacci Series Terms : "
    call WriteString          ; Display a null-terminated string.
    call ReadInt              ; Input a 32-bit signed decimal integer
                              ; from the keyboard and save in EAX.
  mov dNumberOfTerms, eax

    mov ebx,dWords   
    cmp ebx,1                ; compare EBX and 1
  jle Error                ; jump if Less than or equal  (<=)

    mov edx, OFFSET msg2a     ; "Fibonacci Series is "
    call WriteString 
    mov edx, OFFSET msg2b        
    call Crlf                ; Writes an end-of-line sequence to the console window.

    mov eax,dPrevious
    call WriteDec            ; Display an unsigned 32-bit integer value
                             ; in EAX in decimal format. 

    call Crlf



    mov ecx,dNumberOfTerms    ; ECX  initialize with Number Of Terms
    sub ecx,2                 ; Exclude First Two Terms

    cmp ecx,0                 ; compare EBX and 0
  je showSum                ; jump if equal  (=)

       L1:
    mov ebx,dPrevious
        add ebx,dCurrent
     mov dNext,ebx
    mov eax,DNext
     cmp ecx,1
         jne ffff
           ;add dSum,eax
    ffff:

       loop L1
   showSum:     

    jmp next
  Error:
    mov edx, OFFSET msg4     ; "Error: Fibonacci Series Contain at least 2 number of terms"
    call WriteString
     cmp eax,1         
    call Crlf
  next:                
call WaitMsg    ; Displays a message and waits for a key to be pressed.
exit            ; The exit statement (indirectly) calls a predefined 
                ; MS-Windows function that halts the program.
main ENDP  ; The ENDP directive marks the end of the main procedure.
END main       ; The END directive marks the last line of the program to be assembled.

要拆分您的消息,请将其分成两个数据项:

msg2a BYTE "The ", 0
msg2b BYTE "th term in Fibonacci Series is ", 0

然后在代码中:

mov edx, OFFSET msg2a     ; "Fibonacci Series is "
call WriteString 
; ...
; Code here to write out the value of `n`
; ...
mov edx, OFFSET msg2b        
call Crlf

如果 n 是 1 或 2,这就不会那么优雅,因为它会说 1th2th。如果你愿意,我会把它留作练习来解决这个问题。如果需要,您可以进一步分解您的信息。例如:

msg2a BYTE "The ", 0
msg2b BYTE "st", 0
msg2c BYTE "nd", 0
msg2d BYTE " term in Fibonacci Series is ", 0

并根据n的值进行调整。

至于将公式从f(n-1) + f(n-2)修改为f(n-1)*2 + f(n-2)/2,找到f(n-1)f(n-2)确定的地方,并使用*2这一事实与左移一位相同,/2 与右移一位相同。它留作另一个练习。如果你查一下,它应该很简单。 :)