flat assembler
Message board for the users of flat assembler.

Index > Windows > FASM OPERTORS

Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Hello, typedef here again with another 'tough' question.

Is it possible to implement an 'object operator' in ASM, using FASM ofcourse.

If there's not way, then thanks.

I just love to implement high levels to low levels. Very Happy I'm trying to implement an operator in FASM from C/C++

C++

Code:
class Foo
{
   public :
             Foo(int x);
 Foo Operator+=(Foo& ptr)
{
  Foo temp;
     temp.x = this.x + ptr.x;

return temp;
 }

};

    


How would you that be implemented in FASM.

The macro way...please, if possible
thanks
Post 10 Feb 2011, 22:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
What do you want to do? What does "Operator" do in the above code? For those of us (like me) with no understanding of C++ the above has no meaning.
Post 11 Feb 2011, 01:18
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Operators are in other terms, "mathematical functions".

They let you assign, increment, decrement, various types of objects.

for a quick glance : http://www.cplusplus.com/doc/tutorial/operators/
Post 11 Feb 2011, 05:15
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
OOP is not a goal in itself. It is a tool, created to help you to achieve your goals.
That is why revolution asked you "What do you want to do?"
The answer is "Yes OOP can be implemented in assembly language".
But because assembly is not HLL this OOP can not be the same as in C++.
You can create macro with name "class" but it will not be "class" in HLL meaning.
For example you can't implement "encapsulation" in assembly because in assembly you always have control over the data.
Post 11 Feb 2011, 05:51
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Thanks JohnFound, you opened my eyes there lol.

I knew in LLL you have control over your data but never tought about it. Thanks very much. I see now that it doesn't make any sense really to be implementing that. However I'm still curious. Is it possible to make a "class" ( via macro) so that you don't need to be calling all the methods again and again. For example

in C++
Code:
class Window
{
 private:           // <---- I know this doesn't matter in LLL
    HWND hHandle;
    WNDPROC myProc;
 public:
    Window ( char* name, char* lpClass,LONG style){
    hHandle = CreateWindowEx(....);
   ShowWindow(hHandle,SW_HIDE);
   }

int Exec()
{
MSG msg = {0}
while( GetMessage(NULL,&msg,0,0) > 0 )
{
   ...
   ...
}
return msg.wParam;
}
void SetProc(WNDPROC wndProc)
{
myProc = wndProc;
}

void Init()
{
WNDCLASSEX wc;
wc...
wc.lpfnWndProc = myProc;

RegisterClassEx(&wc);
}

void SetVisible(bool bVisible)
{
ShowWindow(hHandle,  (bVisible==true) ? SW_SHOW : SW_HIDE );
}

};


LRESULT CALLBACK proc(.....)
{
....
}

in main function
...
Window *wnd = new Window("","",WS_VISIBLE|WS_OVERLAPPEDWINDOW);

wnd->setProc( proc );
wnd->Init();

return wnd->Exec();
    


How would you do that in LLL so you wouldn't have to go through all those methods over and over again ?

I want to create an ASM include file for those classes so I don't have to re-write them (methods ) again. (You know, "code re-use", OOP way Very Happy )
Thanks


Last edited by typedef on 14 Feb 2011, 20:56; edited 3 times in total
Post 14 Feb 2011, 17:40
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
code re-use is not oop only;

C langage is an example of code reuse. because instead of rewrite printf everytime, you just reference it.

asm too is oop if you define it as code re-use capacity.
because you don't have to rewire every circuits each time you call an instruction, and don't have to re-write a funtion, just include it.
Post 14 Feb 2011, 17:46
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Yep, but what I need to know is how to make the macro "class".


Last edited by typedef on 14 Feb 2011, 20:24; edited 1 time in total
Post 14 Feb 2011, 17:54
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
before trying to implement class, try to implement this:
Code:
Foo
{
 Foo(int x);
 Foo Operator+=(Foo& ptr)
{
  Foo temp;
  temp.x = this.x + ptr.x;
return temp;
 }

};
    

class seems to just be a keyword.
apparentlly, class means nothing at all in asm, and only reference the label for your "class" is enough to call it, or read it, or write it, or whatever you want on it.

what does class mean exactlly? how is it represented in mémory? in a file? in a flowchart?

maybe:
Code:
macro class {}
    

is enough, but then, the way to call the class is... please stop, here it is assembly programming forum, post in HLL or macro subforum
Post 14 Feb 2011, 19:58
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
typedef wrote:
How would you do that in LLL so you wouldn't have to go through all those methods over and over again ?


Actually in this very moment I am working on something that can be named "classes" and "objects". It is not OOP. It is simply a natural representation of GUI elements.
You can see the work in progress in FreshLib library; Files from GUI directory.
Post 15 Feb 2011, 08:07
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Say, did you start this along time ago ?
What a coincident.
Post 16 Feb 2011, 19:22
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
You included SQLite too ? You are the man dude.

I really was in need of that sometime ago.

Thanks dude
Post 16 Feb 2011, 19:27
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
sorry double post. But this thing just meets my needs. Code completetion also. Man, 10 out of 10 though you said tis not done yet. Very Happy
Post 16 Feb 2011, 19:29
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
I am glad you are happy. Very Happy
But Fresh is really not finished yet. The old library is not portable, the new one is not ready.
Of course code completion and other editor features works and will work in the future versions. The visual part - forms, components etc. will be changed a lot with the new library. Maybe there will be tool to convert from the old format to the new, but I am not sure.
Post 16 Feb 2011, 19:57
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.