flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > Structures and "Objects"

Author
Thread Post new topic Reply to topic
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
We can make sort-of objects by making a structure with built-in pointers to the procedures, by having a pointer to the procedures, in a struc, but is this very practical? We would probably have to have a bit of macro-programming to say the least, to keep track of which objects are stored at what location, since procedures have variable size. OOP in asm- hard to imagine. Has anyone tried this? And would it be practical? I noticed this here:

http://board.flatassembler.net/topic.php?t=2516

it is pretty interesting, but I wonder about the practicality, let alone the ethics (of destroying all that asm and especially FASM stands for, by making it into OOP) of this type of thing. Just curious what others think about it.

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 17 Mar 2005, 22:33
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3494
Location: Bulgaria
Strange, but almost everyone, when learn enough FASM macro system, tries to implement OOP or some other type of HLL using macroses. Wink It is not bad as a good exercise, but actually it is not very practical for real life applications IMHO.
Actually the nature of the assembler is "procedural" and to try to make it "object oriented" means a lot of code and data overbloat and slower execution.
Macro features have to be used extreamly carefully in minimal usefull quantity, because macro solutions have advantages (smaller and compact code), but have disadvantages too (less clear code - especially for very complex macroses) and the best approach is "modest" one.

Regards
Post 18 Mar 2005, 00:15
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
JohnFound, FASM macro system let implement OOP without slower execution. I have made a RadASM template for COM inproc server using my OOP macroses (but I have not implemented multiply inheritance yet, so it generates VTable only for one class). It generates only fields and VTable (you can declare any static methods too). As for me, it is very good solution, because you have no need to write VTable manually. And of course speed and size with FASM are the best (3K for server, which do something, with registration and deregistration from registry).
I think that OOP macroses with careful attention can do the best with FASM.
Regards.
Post 18 Mar 2005, 06:45
View user's profile Send private message Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
I don't think it's very practical either; however, as Privalov mentioned, with careful attention it can become a great asset and tool, and would not necessarily bloat code unneedingly. Macros are, after all, a very powerful feature of FASM, and of other languages which support them. However, it would take an experienced macro-programmer (I'm not one) to do this sort of thing... maybe someone should make an open-source FASM macro-library for OOP, that anyone can use. Once again, though, must applications probably would be more simple to program in some ways, using normal "traditional" assembly language- I mean, FASM is a procedural assembly language, after all, and not an HLL. Let us try to remember this, but at the same time, try to use OOP if it would make programming easier, more inuitive, etc. There are many advantages and disadvantages to using OOP - I wonder if FASM Macro OOP is true OOP...

_________________
FASM Rules!
OS Dev is fun!
Pepsi tastes nasty!
Some ants toot!
It's over!
Post 18 Mar 2005, 16:20
View user's profile Send private message AIM Address Reply with quote
rea



Joined: 14 Nov 2004
Posts: 92
There is a interesting topic somewere in to win32 community about OO and ASM Wink, cant find it, but is there Wink.
Post 18 Mar 2005, 21:52
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
problem with assembly-newbies is that they try to code assembly way they are used with previous HLL languages. But coding in assembly is another approach, just like Pascal (procedural) <--> Java (object-oriented)
Post 18 Mar 2005, 22:52
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
THEWizardGenius



Joined: 14 Jan 2005
Posts: 382
Location: California, USA
I agree, I prefer traditional assembly. I say to any newbie who wants certain features that are from HLL's, "Why did you switch to ASM if you want that? Go back to your HLL if you really want to." However, there are certain features that can make the programming easier and faster, without making it slow. OOP is one such feature. If used properly, it can be very helpful, and not slow the program down much if at all. Other than the fact that it's against traditional assembly, what is wrong with using OOP or OOP-like structures? We have macros, structures, and other things, which make programming easier without making the program slower. Let's not try to write programs in machine language or debug... FASM is constantly evolving, in good ways. We have no built-in procedures, such as "PRINT" (BASIC) or "scanf" (C), or similar things, but we do have macros, structures, and other things. The goal is to make the task of the programmer easier without impairing speed of the output program. Am I mistaken, or isn't this what FASM is all about?
Post 19 Mar 2005, 05:50
View user's profile Send private message AIM Address Reply with quote
rea



Joined: 14 Nov 2004
Posts: 92
When you read such topic, pheraphs and I hope that point of view that a hll is equivalent to a paradigm change Wink....
Post 19 Mar 2005, 15:13
View user's profile Send private message Reply with quote
rea



Joined: 14 Nov 2004
Posts: 92
OK, the OOP forum is that one the thread Im refering to
http://217.160.247.193/index.php?topic=20682.0

Hope that one help a little Wink.

HLL is diferent than a paradigm Wink one dosent implicate the other.

The point is that a programmer only think in a paradigm in terms of HLL and not the paradigm itself.
Post 24 Mar 2005, 16:14
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
I think THEWizardGenius got the point for OOP.

FASM is a bit more high level than HLL in some aspects, for me the fact that statements are the real machine instructions is detail. It already provides a macro system, so why worry with data definitions if you don't need? I can't see why the proc/stdcall macro is better than OOP. OOP hides the burden of definining and initializing data. With OOP overall performance and coding speed can be faster, as you program in a more natural way(I feel this), and avoids that fat case statements. Also it provides a modular, component-based approach. Is obvious the beneficts. More understandable, mantainable code.

In my opinion, the current trend among FASM users, i.e. stdcall, is that generates fat, slow code. This was the reason why I researched a way to provide alternatives to that. I not applied on AsmOO yet(may take a long time till there), but the results was posted here. Very good, btw.

So, OOP IS very pratical. At first, OOP in asm seems impossible, mainly because it needs some compiler-feeded information, but FASM macro system does that job.

_________________
"I assemble, therefore I am"

If you got some spare time, visit my blog: http://www.beppe.theblog.com.br/ and sign my guestmap
Post 28 Mar 2005, 22:29
View user's profile Send private message Reply with quote
ezanahka



Joined: 10 Jul 2005
Posts: 3
OOP in asm? Why? Because OOP provides more abstraction and that makes programming easier?
It is true. Objects do provide abstraction. Sometimes they give more abstraction than what you bargained for and workaround are always annoying.

And why oh why... OOP == C++ Java etc...???
Aren't CLOS, Dylan, Smalltalk, etc. OOP?

"a structure with built-in pointers to the procedures"
Why should a procedure belong to datatype? Why not bundle procedures under generic functions?

What I'm trying to say that OOP isn't a well-defined target and its not the only way to get more abstraction. There are a lot more paradigms in programming that just hardware-oriented, object-oriented and procedural... There are more than just one way to use function pointers after all.

So... has anyone succeeded in writing decent OO code with asm?
With multiple inheritance? Wink
Post 10 Jul 2005, 15:43
View user's profile Send private message Reply with quote
KronosRJ



Joined: 03 Jul 2005
Posts: 15
The only thing I ask for is that, should there be any improvements on this, please distribute to other users.

Use:
For each class, you SHOULD create an .inc and an .asm file.
This OO INCLUDES INHERITANCE.

For the .inc:

Code:

Class Base
        ClassStartData
                .m_cRefs        dd ?
                .m_pvMain       dd ?
        ClassEndData
        ClassStartProc
                Proc Constructor
                Proc Destructor
                Proc ToString           
                Proc QueryInterface
                Proc AddRef
                Proc Release
        ClassEndProc

EndClass
    


For the .asm file:
Code:
format MS COFF
DECLAREDCLASS fix JRBBase
include 'Base.inc'
section 'code' code

ClassDeclaration JRBBase

PROCOBJ Constructor , EDXTHIS
        mov [this + JRBBase.m_cRefs] , dword 1
        mov [this + JRBBase.m_pvMain], dword 0
ENDPROCOBJ 1

PROCOBJ Destructor
ENDPROCOBJ 1

PROCOBJ ToString , EDXTHIS
        Param a_pjosOutput
ENDPROCOBJ 2

PROCOBJ QueryInterface , EDXTHIS
Param a_pidIID,a_ppvObj
ENDPROCOBJ 3

PROCOBJ AddRef
ENDPROCOBJ 1

PROCOBJ Release
ENDPROCOBJ 1

EndClassDeclaration
    


Now, some considerations:
I intend to create classes that I might use with COM in the future. Thus, I intend to the methods Constructor,Destructor,ToString as negative offsets in the function table; this is not implemented yet.
Error handling for Win32 is not implemented yet (in my idea, a MUST HAVE). I have already implemented it in another library, but I must reimplement it in this one.
I had implemented the begining of a library exactly like this in Nasm. The problem is, since I couldn't have the function table (with inheritance), I had a very high development cost in time due to misplacements in the function table. I think this is the main thing in a library like this.
Hope everybody enjoys.


Description:
Download
Filename: OO.zip
Filesize: 2.06 KB
Downloaded: 115 Time(s)

Post 20 Jul 2005, 21:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
well, OOP seems good in general but there are some special cases where result is really unclear and unpredictable, depending only on imptementation of basic OOP paradigms, and this implementation can differ. Also it IS abstraction and thus overbloat, processor doesn't work with object, it works with linera code and stack. Just like structured programming is overbloat, but not that ugly.

Also you cannot always have clear hierarchy, even if you are anyhow good, in real big project there isn't such thing, sometimes you really need to access something which is at-first-sight not releated. Then if you want to solve this in OO manner, solution is ugliest possible, and other things like objects which have no "real" represantion in resulting program (designed just to workaround OOP restictions) or "friends" are ugly and hard-to-understand too. It is nice idea but not always working, unlike our style of linear/procedural programming.
Post 20 Jul 2005, 21:59
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Raedwulf



Joined: 13 Jul 2005
Posts: 375
Location: United Kingdom
Hmmm procedural programming, yeah I kinda agree Smile
I'd forsake oop if it wasn't used in c++ and other languages Razz

But for the oop side ...why don't we port this to fasm Smile

http://objasm32.tripod.com/index.htm
Post 21 Jul 2005, 19:04
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
Quote:
The last good thing written in C was Franz Schubert's Symphony No. 9.

Smile
Post 22 Jul 2005, 07:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger 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-2019, Tomasz Grysztar.

Powered by rwasa.