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

avatar

(send private message)

Posts: 933
Topics: 55

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: 639
Topics: 104

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: 933
Topics: 55

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 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd