flat assembler
Message board for the users of flat assembler.

Index > Main > Backwards virtual

Author
Thread Post new topic Reply to topic
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 27 Aug 2004, 21:59
Just wondering if such a thing exists.

I have been using virtual mainly for procedures and local variables, and i usually implement it like this:

Code:
myproc:
virtual at esp
  i dd ?
  x dd ?
end virtual

push ebp
mov ebp, esp
sub esp,8

mov [i], eax
mov [x], 50

mov esp, ebp
pop ebp
ret
    


I was hoping for a backwards virtual, something like this:
Code:
myproc:
backwards_virtual at ebp
  i dd ?
  x dd ?
end virtual

push ebp
mov ebp, esp

mov [i], eax
mov [x], 50

mov esp, ebp
pop ebp
ret
    


For one, i won't have to worry about the amount and sizes on the stack, and because it is backwards, i won't have to do sub esp, (sizeof the virtual block) so that the code follows the backward stack.

Thx.
Post 27 Aug 2004, 21:59
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Aug 2004, 09:41
seems you didn't really comprehend what is "virtual", only one of it's usages.
First of all, you have to reserve space on stack for variables (sub esp), otherwise you will overwrite something other or something other will overwrite your variables.
Post 28 Aug 2004, 09:41
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 28 Aug 2004, 16:58
That is the point. If virtual went backwards, the stack wouldn't be a problem.

Anyway, as long as you don't push/pop or call a function in the function, then there really is no loss, and it would be easier to have the second code over the first code.

And if you saw the first code, the one which i do right now, i did do sub esp, 8.
Post 28 Aug 2004, 16:58
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Aug 2004, 19:11
now i get what you wanted. Look at fasm's proc macro. You can use forward reference to get size of local data and then sustract size from base of virtual block, like:
Code:
;in macro
local ..from, ..size
virtual at ebp - ..size
  ..from = $
  a dd 0
  b dd 0
  ..size = $ - ..from
end virtual
    
Post 28 Aug 2004, 19:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Aug 2004, 19:13
you wanted this?
Code:
;must be in macro
local ..from,..size
virtual at ebp - ..size
  ..from:
  a dd ?
  b dd ?
  ..size = $ - ..from
end virtual
    
Post 28 Aug 2004, 19:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 28 Aug 2004, 19:28
What about this?
Code:
macro back_virtual_at x {
  local ..start, ..end
  ..1 equ ..start
  ..2 equ ..end
  virtual at x - ..2
    ..1:
}

macro end_virtual {
    ..2 = $ - ..1
  end virtual
  restore ..1
  restore ..2
}

back_virtual_at ebp
  a dd ?
  b dd ?
end_virtual

mov [a],eax
mov [b],ebx    


Last edited by Tommy on 28 Aug 2004, 19:47; edited 2 times in total
Post 28 Aug 2004, 19:28
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 28 Aug 2004, 19:34
Better use "restore ..1" instead of "..1 equ" - this way you can even make these macros nestable.
Post 28 Aug 2004, 19:34
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy 28 Aug 2004, 19:47
Thanks for pointing that out Privalov! Smile
Post 28 Aug 2004, 19:47
View user's profile Send private message Visit poster's website Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 29 Aug 2004, 17:18
Wow. Fasm macros impress me again!!
Post 29 Aug 2004, 17:18
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.