flat assembler
Message board for the users of flat assembler.

Index > Main > Proc-endp replacement

Author
Thread Post new topic Reply to topic
booter



Joined: 08 Dec 2006
Posts: 67
booter 12 Jul 2009, 13:09
To me the most chellenging in writing in FASM is kind of controversy in using Proc-endp. Let's take a look
Code:
a dd ?
mov eax,a    

Inside procedure it becomes
Code:
proc T1
  local a:DWORD
  mov eax,[a]
  ret
endp    

Parameters create similar problem
Code:
proc T2 x
  mov eax,[x]
  ret
endp    

And it's always confusing when calling
Code:
a dd ?
stdcall T2,[a]  ;?
stdcall T2,a  ;?
stdcall T2,addr a  ;?    

Let's write replacement to Proc-endp (and "local") that would allow coding inside its body the same way as outside (like macros). I mean something like this
Code:
a dd ?
sub TN b
  var c dd ?
  mov eax,a
  mov ebx,b
  mov ecx,c
  return
esub    
Post 12 Jul 2009, 13:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 12 Jul 2009, 13:13
But inside a procedure the incoming and local parameters are EBP based so using mov ebx,b means you have to override the mov opcode. It becomes very messy, but you are welcome to try if you want a challenge.
Post 12 Jul 2009, 13:13
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 12 Jul 2009, 17:02
It seems there's been some confusion here. The "mov eax,[a]" inside a procedure is NOT an equivalent of "mov eax,a" outside it. Actually, these things work very similarly in both cases:
Code:
a dd ?
mov eax,[a]    

Code:
proc T1 
  locals
   a dd ?
  endl
  mov eax,[a] 
  ret 
endp    
Post 12 Jul 2009, 17:02
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 12 Jul 2009, 18:39
Code:
virtual at ebp-16
     .b rd 1
end virtual

struc eax [a]{
   common 
     . eax a
}

mov eax,[.b]
add eax,[.b]    
Very Happy This trick covers a lot of ground for creative syntax choices.
Post 12 Jul 2009, 18:39
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 15 Jul 2009, 22:39
booter,

Probably you're used to MASM syntax/semantics of symbolic names; here in fasm we use label to refer to the address and [label] for memory contents at that address. Procedure-local variable doesn't have compile-time address, thus you can't compile something like mov eax, a where a is a proc-local var. Use lea eax, [a] instead (if you really need the address). Quick tour on old (i.e. around 1.53) INCLUDE\MACRO\STDCALL.INC will help (and increase your macro expertise as well Wink).

Tomasz Grysztar,

mov eax, [a] is not equivalent to mov eax, a in any occurrence (heavy macro beside), aren't they? Wink


bitRAKE,

AFAIK eax will not be treated as macro/struc name in that context, so no cookie. Wink
Post 15 Jul 2009, 22:39
View user's profile Send private message Reply with quote
booter



Joined: 08 Dec 2006
Posts: 67
booter 16 Jul 2009, 05:40
baldr wrote:
booter,
Procedure-local variable doesn't have compile-time address, thus you can't compile something like mov eax, a where a is a proc-local var. Use lea eax, [a] instead
Tomasz Grysztar,

Yes, that's the problem with local variables and parameters!
However actually it may be a problem with assembler, which requires lea mnemonic/syntax instead of compiling
Code:
mov eax,ebp+N    
exactly the same way as it does for
Code:
lea eax,[ebp+N]     


Tomasz,
How to recognixe register+N operand in a macro?
Thanks

BTW, as I understand we can't base data by ebp, I mean [ebp:N] is not legal.
Post 16 Jul 2009, 05:40
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 16 Jul 2009, 08:19
booter wrote:
Tomasz,
How to recognixe register+N operand in a macro?
Thanks

Check out how "pushd" macro from win32ax.inc does it:
Code:
   virtual at 0
    label ..address at var
    mov eax,dword [..address]
    load ..opcode from 0
   end virtual
   if ..opcode = 0A1h
    push var
   else
    lea edx,[..address]
    push edx
   end if
    
Post 16 Jul 2009, 08:19
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 16 Jul 2009, 14:48
baldr wrote:
AFAIK eax will not be treated as macro/struc name in that context, so no cookie. Wink
Try it and see. Now, where is my cookie? Razz

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 16 Jul 2009, 14:48
View user's profile Send private message Visit poster's website 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.