Author Topic: Using the stack between lines of Basic code  (Read 2306 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Using the stack between lines of Basic code
« 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
« Last Edit: June 24, 2012, 10:58:14 AM by Charles Pegge »

Peter

  • Guest
Re: Using the stack between lines of Basic code
« Reply #1 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 !

Charles Pegge

  • Guest
Re: Using the stack between lines of Basic code
« Reply #2 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