Register | Login
Forum Index > Samples > Creating a temporary variable
Author Message
Pages: 1
Admin
Site Admin

avatar

(send private message)

Posts: 923
Topics: 54

Location:
OverHertz Studio
[824] Creating a temporary variable - posted: 2011-11-24 18:59:49
Lets say you need a temporary variable, but you want to create it inside an inline or macro you could use several options such as using inherited variables or globals however probably the best option would be like so:

Code:
// First we will push a 0 integer onto the stack
// If you require a pointer to an int, then push your int value instead.
push 0

// esp is the pointer to the stack which is the top value (latest push)
// the stack is is 4 byte aligned (int or dword size)
myFunction(esp);

// finished with the int, remove it from the stack without trashing a register
add esp, 4


a sample of it in use would be the filewrite macro:

Code:
inline function filewrite(handle, text, len) {
      push eax
      WriteFile($handle,$text,$len,esp,0);
      add esp, 4
      
      $return eax;
}


in this case the WriteFile api requires a pointer to a dword to write the written byte count, filecreate does not use it so we can just use the temporary solution as so.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 638
Topics: 103

Location:
Alex, Egypt
[825] - posted: 2011-11-24 19:11:15
nice article ,

instead of push you can use this
Code:
 sub Esp,4
or
 Esp -= 4;


and that is useful if you need more than 4 bytes local variable inside macro so you can allocate it as that
Code:
sub Esp, 16 // 16 bytes variable



http://www.freewebs.com/ogremagic/index.htm
Admin
Site Admin

avatar

(send private message)

Posts: 923
Topics: 54

Location:
OverHertz Studio
[828] - posted: 2011-11-24 19:27:06
absolutely, but it should be noted that if it is for a 4 byte var then push is smaller smile

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 17 user(s) online. 0 member(s) and 17 guest(s)
Most users ever online was 533, May 5, 2016, 7:19 am.


Statistics:
Threads: 223 | Posts: 1835 | Members: 49 | Active Members: 49
Welcome to our newest member, pierrotstudio
const Copyright = '2011-2017 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd