Programming => Example Code => General => Topic started by: Charles Pegge on June 24, 2012, 09:16:20 AM
Title: Using the stack between lines of Basic code
Post by: Charles Pegge on June 24, 2012, 09:16:20 AM
You can use the stack directly, mixed in with Basic.
Code: OxygenBasic
function f()
sys a=1,b=2,c=3,d=4
push a
push b
push c
push d
print a "," b "," c "," d 'result 1,2,3,4
a=10
b=20
c=30
d=40
print a "," b "," c "," d 'result 10,20,30,40
pop a
pop b
pop c
pop d
print a "," b "," c "," d 'result 4,3,2,1
endfunction
f
Charles
Title: Re: Using the stack between lines of Basic code
Post by: Peter on June 24, 2012, 09:53:52 AM
Hi Charles,
Thanks for that. Can be useable !
push a push b push c push d
pop d pop c pop b pop a
This would be correct !
Title: Re: Using the stack between lines of Basic code
Post by: Charles Pegge on June 24, 2012, 10:48:33 AM
Yes. But watch out for undeclared cdecl calls in between, they will trash the stack.
Oxygen functions are normally tolerant of small numbers of cdecl calls because the esp register is restored from the ebp register at in the function's epilog.