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?

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

.code
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)
exit
main ENDP

DisplaySum PROC
call WriteInt			; Display number
mov edx, OFFSET string	; add space between the numbers
call WriteString
ret
DisplaySum ENDP
 
END main

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.