flat assembler
Message board for the users of flat assembler.

Index > Main > masm to fasm for newb

Author
Thread Post new topic Reply to topic
chorus



Joined: 16 Mar 2004
Posts: 23
chorus
Hello all,
I've downloaded fasm and think it's wicked (nice job Privalov) and I'm converting my old masm syntax code to fasm. Naturally, there are some differences. I've taken a quick look through this board but didn't really find the answers that I was looking for (I'm sure they're here somewhere...)

I have 3 problems I'm trying to address. Can someone please help me out?

1) How do you declare a local stack variable for a proc? in masm I would do
Code:
MyProc proc a,b:dword
LOCAL whatever:dword
    


2) How do you get the size of a structure? ex.
Code:
mov wc.cbSize, sizeof WNDCLASSEX
    


3) How do you use a reg as a pointer to a struc? ex.
Code:
mov [ebx].WNDCLASSEX.cbSize,48
    

How would you assume it?

If anyone could let me know how these things can be done I'd greatly appreciate it.

Thanks
--Chorus
Post 16 Mar 2004, 16:28
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
1. use proc macro
Code:
proc MyProc,a,b
 dd wathever
 begin
 mov eax,[wathever]
 add eax,[a]
 return
endp
    

2. use struct macro
Code:
 mov [wc.cbSize],WNDCLASSEX
;or
 mov [wc.cbSize],sizeof.WNDCLASSEX

    


3. use virtual directive
Post 16 Mar 2004, 16:44
View user's profile Send private message Yahoo Messenger Reply with quote
chorus



Joined: 16 Mar 2004
Posts: 23
chorus
Thanks! Seems simple enough Smile

Just to make sure though, with the "dd" syntax for a local that does define it as a variable on the stack right? As opposed to defining a dword in the middle of my code?

--Chorus
Post 16 Mar 2004, 17:10
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
chorus wrote:
Thanks! Seems simple enough Smile


Well, here are some details. Smile There is standard macro library in FASMW package that provides macroses for these constructions: proc, struct, invoke, stdcall etc.
Its syntax is a little diferent from the above examples:

Code:
proc ProcName, arg1, arg2, .... argN
; local variables, they will be created in the stack.
  .name1 dd ?
  .name2 dd ?
  .name3 rb 100 ; you can use every data definition instruction here.
enter
   ; the body of the procedure.
return
    


Because of some reasons (more power and flexibility) the project Fresh and developers working on FASMs standard library prefere to use a little bit different proc definitions:
Code:
proc ProcName, arg1, arg2, .... argN
; local variables, they will be created in the stack.
  .name1 dd ?
  .name2 dd ?
  .name3 rb 100 ; you can use every data definition instruction here.
begin
  ; the body of the procedure.
      return

 ; possibly another code
      return
endp
    


You can download this variant from Fresh package here:
http://fresh.flatassembler.net

Also I prefer to not use following construction:
Code:
 mov [wc.cbSize],WNDCLASSEX    


It is absolutely equivalent to:
Code:
mov [wc.cbSize],sizeof.WNDCLASSEX    

but, "sizeof." variant is more readable and clear.

About using structures with register indirect addressing:
Code:
    mov  [esi+WNDCLASSEX.cbSize], sizeof.WNDCLASSEX    


FASM is very flexible to do this kind of things, so after some experience, you will find the most comfortable for you way.

Regards.
Post 16 Mar 2004, 17:34
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
chorus



Joined: 16 Mar 2004
Posts: 23
chorus
Thank you JohnFound. Details are good. I like details Smile

Another question: How can I pass local variables to a proc through invoke?

I try to do this:
Code:
proc InitClass,lpszClassName,lpfnWndProc,hIcon
.wc WNDCLASSEX
        enter
        ...
        invoke RegisterClassEx,.wc
        return
    


but the invoke to RegisterClassEx does not assemble. I have to "lea eax,[.wc]" and then "invoke RegisterClassEx,eax" (the same thing, I know, but it would be convenient to not have to do that).

Thanks again
--Chorus
Post 16 Mar 2004, 20:06
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
chorus wrote:
Another question: How can I pass local variables to a proc through invoke?....
I have to "lea eax,[.wc]" and then "invoke RegisterClassEx,eax" (the same thing, I know, but it would be convenient to not have to do that).


This is not "the same thing". It is the "only way" to make it. MASM provide this behaviour hidden from the programmer. Of course it is possible to make the same behaviour for invoke macro for FASM, but I don't think this is good programming practice, for assembler.

Regards.
Post 16 Mar 2004, 20:14
View user's profile Send private message Visit poster's website ICQ Number 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-2020, Tomasz Grysztar.

Powered by rwasa.