Oxygen Basic

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
  1. function f()
  2.   sys a=1,b=2,c=3,d=4
  3.   push a
  4.   push b
  5.   push c
  6.   push d
  7.   print a "," b "," c "," d 'result 1,2,3,4
  8.  a=10
  9.   b=20
  10.   c=30
  11.   d=40
  12.   print a "," b "," c "," d 'result 10,20,30,40
  13.  pop a
  14.   pop b
  15.   pop c
  16.   pop d
  17.   print a "," b "," c "," d 'result 4,3,2,1
  18. end function
  19.  
  20. f
  21.  

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.

To test whether a call is Cdecl:

a=esp
call suspectedCdeclFunction ....
print esp-a

if you don't get zero then there is junk left on the stack.


Charles