News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

classes help

Started by 0x401000, June 21, 2011, 02:27:40 PM

Previous topic - Next topic

0x401000

Explain somebody please, how classes work and what it is to assembler example, I have always programmed in assembly language, and now the classes are having difficulty understanding, can not understand what is their beauty and how to write assembly language programs in the form of classes. Revised examples, read the description in the books, looked at how to collect the classes C + + and still do not understand =((((( Thanks!

Tedd

You have a magic box of a certain type (class) and it can do specific things for you (depending on the type). It offers functionality to you (methods) for the things you can ask of it. You don't know how it works inside, and you don't need to, as long as it does what you want then you can just use it as is.
Inheritance is simply making a new type of box that extends (and hopefully improves) the utility of a box, building on top of another box (base class.)
And then someone can use your new improved box in place of the old one, without changing anything - since it still does everything the previous one did (and more.)

As for implementation, it's nothing more than a set of functions, with some variables allocated for each box you create (instance.) The constructor and destructor are special functions that create and delete the box. Methods are also functions, but they take an extra parameter of a pointer to the object instance ('this'), so they can perform their function on it.

If you really need it, I could make a small example.
Or you can take a look at http://objasm32.tripod.com/
No snowflake in an avalanche feels responsible.

baltoro

There was a thread about this recently,...the thread is here: Clipping rectangles with use of MMX instruction set

Quote from: Jarekfall...You can implement any type of C++ class member functions (methods) in pure assembly language, apart from functions of inline type. Names stored in files of LIB and OBJ type have global scope. The only drawback of this is that the implemented in assembly language functions must be used only with that C++ compiler which uses the same calling conventions as those which have been used in those implemented functions,...

Jarekfall's Website has this explanation and axample:  Implementing C++ class methods in pure assembly language in Microsoft Visual C++ and MASM

Classes don't exist (explicitly) in MASM assembly language,...they are a feature of C++ (and, other high-level languages). In assembly language, the equivalent would be a structure,...and, some associated functions.
Baltoro

Twister

You can export the symbols from C++ libraries to use in an assembly program. You will get mangled names, but it still works though.

_ZN9wikipedia7article8wikilinkC1ERKSs (std::string const& name)

http://en.wikipedia.org/wiki/Name_mangling

redskull

Conceptually, it's just an association between a data structure and a set of functions.  Fancy languages have fancy syntaxes that make it appear as though they are one-in-the-same, but all that's happening when you call

MyObject.MyFunction(foo)

is the compiler turns it into

invoke MyFunction, ADDR MyObject, foo

It just a syntax to help you organize the sprawl of functions and global data.  Its damn useful, too, if you use it the right way.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Quote from: redskull on June 21, 2011, 11:11:54 PM
Fancy languages have fancy syntaxes...

red, you hit the nail on the head. "Classes" is just a preposterous swollen word for good ol' invoke combined with some structures :bg

> Strange women, lying in ponds, distributing swords, is no basis for a system of government
Who she? Dilma, Hillary, Angela?  :wink

redskull

Quote from: jj2007 on June 22, 2011, 06:19:36 AM
"Classes" is just a preposterous swollen word for good ol' invoke combined with some structures :bg

Though, to be fair, once you get into type extension and virtual functions there is a whole lot more going on behind the scenes, but it's still just pointers under the hood.

Quote from: jj2007 on June 22, 2011, 06:19:36 AM
Who she? Dilma, Hillary, Angela?  :wink

I suppose it could be any (or all) of them.  :bg

http://www.youtube.com/watch?v=dOOTKA0aGI0
-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government


jj2007

Quote from: redskull on June 22, 2011, 08:54:18 PM
I suppose it could be any (or all) of them.  :bg

http://www.youtube.com/watch?v=dOOTKA0aGI0
-r

Great link, thanks. I had not recognised the quote because a) I saw most of the Monty Python movies some 40 years ago and b) in German :bg

redskull

Quote from: Tedd on June 21, 2011, 03:11:34 PM
someone can use your new improved box in place of the old one, without changing anything - since it still does everything the previous one did (and more.)

Also, FWIT, when pedants talk of the "beauty" of classes, they are usually refering this idea.  If you stop at the basic "groups of functions and data", you will probably never see the beauty of which they speak.  I never saw what all the OOP fuss was about until i saw this in action, and was suitably amazed afterwards.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government