अंतहीन अनगिनत त्रुटियों के लंबे सत्र के बाद, उम्मीद है कि यह अंतिम है।विधानसभा में फिबोनाची श्रृंखला x86
कोई संकलन या रनटाइम त्रुटियां, बस एक तार्किक त्रुटि।
संपादित करें: (फिक्स्ड स्यूडोकोड)
मेरे स्यूडोकोड:
first = 1;
second = 1;
third = 0;
for i from 1 to n{
third=first+second
first=second
second=third
}
return third
इस श्रृंखला का अंतिम परिणाम मुद्रित होगा।
मेरे विधानसभा कोड:
आउटपुट:: Loop Ran : 10 Times -----Final Number is : 11 ------
मैं टिप्पणी नहीं जहां कभी संभव
.386
.model flat,stdcall
option casemap:none
.data
timestell db "Loop Ran : %d Times -----",0 ;format string
fmtd db "%d",0
finalprint db "Final Number is : %d ------",0 ;format string
times dd 0Ah ;times to loop
first dd 1h
second dd 1h
third dd 0h
.data?
retvalue1 dd ? ;we will initialize it later
.code
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
includelib MSVCRT
extrn printf:near
extrn exit:near
public main
main proc
mov ecx, times ;loop "times" times
mov eax,0 ;just to store number of times loop ran
top: ;body of loop
cmp ecx, 0 ;test at top of loop
je bottom ;loop exit when while condition false
add eax,1 ;Just to test number of times loop ran
mov ebx,first ;move first into ebx
add ebx,second ;add ebx, [ first+second ]
mov third,ebx ;Copy result i.e ebx [first+second] to third
xor ebx,ebx ;clear for further use
mov ebx,first ;move first into ebx
mov second,ebx ;copy ebx to second [NOW second=first]
xor ebx,ebx ;clear for later use
mov ebx,third ;move thirs into ebx
mov second,ebx ;copy ebx to third [NOW second=third]
xor ebx,ebx ;clear it
dec ecx ;decrement loop
jmp top ;Loop again
bottom:
mov retvalue1,eax ;store eax into a variable
push retvalue1 ;pass this variable to printf
push offset timestell ;pass Format string to printf
call printf ;Print no. of times loop ran
push third ;push value of third to printf
push offset finalprint ;push the format string
call printf ;Print the final number
push 0 ;exit gracefully
call exit ;exit system
main endp
end main
कोड अच्छी तरह से चलता है, लेकिन उत्पादन मुझे संतुष्ट नहीं है जोड़ लिया है
सबसे पहले मैं rea नहीं हूँ कृपया सुनिश्चित करें कि अंतिम संख्या दशमलव या हेक्स रूप में है।
- दशमलव के रूप में यह मान लिया जाये कि: फाइबोनैचि सीरीज 11
- हेक्स के रूप में यह मान लिया जाये कि नहीं है: फाइबोनैचि सीरीज नहीं है 17 (11 हेक्स = 17 dec)
मैं क्या कर रहा हूँ गलत?
अनिश्चित अगर मुद्रित संख्या में है होना करने के लिए कोई ज़रूरत नहीं के लिए एक काम कोड पोस्टिंग कर रहा हूँ दशमलव। 'printf' प्रारूप के रूप में 'फाइनलप्रिंट' स्ट्रिंग का उपयोग करता है, और यदि यह नियमित 'printf' जैसा कुछ भी है, तो यह दशमलव के रूप में आउटपुट के लिए'% d' का उपयोग करेगा। – usr2564301
बस अपनी टिप्पणियों की तुलना करें जो आप वास्तव में करना चाहते थे;) 'अब दूसरा = पहला' हाँ, लेकिन आप 'पहला = दूसरा' चाहते थे ... ओह। आपको टिप्पणी करने के लिए +1 मिलता है, इस प्रकार हम आपकी त्रुटि को खोज सकते हैं। – Jester
नोट: छद्म कोड सही फाइबोनैकी संख्या देता है, हालांकि एन = 10 के लिए यह '144' लौटाता है, तकनीकी रूप से * 12 वीं * फिब संख्या (या' 89', 'एन' कैसे शुरू होता है, इस पर निर्भर करता है, लेकिन यह अभी भी एक बहुत दूर है)। – usr2564301