I have this program doing the fibonacci and I'm trying to implement the stacks and I think I'm doing it wrong because even if I comment out the push and pop calls it will still display the right numbers, any suggestions?

count DWORD 12			; Number of loops to perform
val1 DWORD ?
string byte (" "),0		; use for the space between numbers

main PROC
mov ecx, count			; loop counter
mov eax, 0
mov val1, 1

ADDLOOP: ; First time loop:
mov ebx, val1
mov val1, eax			; save current eax for our next addition
add eax, ebx
push eax
pop eax
call DisplaySum
loop ADDLOOP			; If not done, perform loop again (ecx is automatically decremented)
main ENDP

DisplaySum PROC
call WriteInt			; Display number
mov edx, OFFSET string	; add space between the numbers
call WriteString
DisplaySum ENDP
END main
9 Years
Discussion Span
Last Post by Narue

>even if I comment out the push and pop calls it will still display the right numbers
Clearly. Your use of the stack is effectively a no-op because you push eax onto the stack, then immediately pop the value off of the stack and back into eax. The state of the program hasn't changed in any way after or between those two instructions.

Generally when you use the stack, you're saving values for later and freeing up the registers for immediate use.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.