flat assembler
Message board for the users of flat assembler.

Index > Main > How implement class in fasm?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
I read about calss c++ that:
Class this is struct. First Vtbl(pointer to list class functions) and data.

Code:
class Object
{
int a,b;
public:
void GetRekt();
void Spawn();
};
    

Struct Object look:
Code:
Vtbl dd pFuns ;i think c++ create interface for pFuns offset.
      a dd 0
      b dd 0
pFuns dd GetRekt,Spawn
    

Interface Object,\
GetRekt,Spawn
Post 20 Aug 2020, 17:43
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
Class & object in HLL are usualy fixed size structures most of its fields are pointers to arrays, other field are count of items of such arrays.
for ex.
Code:
Class:
      intflist dd pIntfList
      fields dd pFields
      parent dd pParent
      classname dd PCharClassName
...
pIntfList dd intf1vtbl
             dd intf2vtbl
             dd intf3vtbl
...
intf1vtbl dd GetRekt,Spawn
...
pFields dd a,b    
Post 20 Aug 2020, 20:12
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
Quote:

fields dd pFields

Its pointer to struct ?

And why need in pIntfList intf2vtbl and intf3vtbl ?
Post 21 Aug 2020, 04:46
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
And about inheritance one class from another.
I think new class(let say B) get from old (let say A) this:
Vtbl dd pFuns ;i think c++ create interface for pFuns offset.
a dd 0 ;struc class A
b dd 0
pFuns dd GetRekt,Spawn

And apply new functions in pFuns and put new values in struct A
Post 21 Aug 2020, 05:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17624
Location: In your JS exploiting you and your system
revolution
If you are interfacing to HLL classes then check your compilers documentation for how it implements classes. Not all compilers generate the same format.
Post 21 Aug 2020, 05:16
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
Main question how class will simplify and where can't do without class ?
implement class or not implement class ? Be or not to be ?!
Post 21 Aug 2020, 05:27
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
Classes needed only in case thou want to HIDE something.
Interfaced proveded by OSes are not more complex actualy.
But when thou wrap it all in classes thou became owner of sacred knowledge hidden from lazy ones.
Lazy programmers mostly just use thour class only on level of understanding interface that thour class provided whithout searching deeper what class actualy does.
Class is more friendly for documenting it or for understanding it by managers far from programming.
But when thou make something for thour own (or for skilled programmer community) classes are absolutely useless.
When thou port something from HLL to assembly thou could provide classes too (but it is wrong way. it usefull only for exploring porting process only, but for porting itself it absolutely uneffective).
Post 21 Aug 2020, 07:29
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
I see few plus in class.
Auto initialization\release.
Couple programers write diferent classes.
Or you write class and using them. Or apply new functions.

My class have two variants.
Its macro and procs.
Procs put in VTBL and macro might do call or do only asm code.
Its more faster.

Code:
;and new macro easy implement in not class field ! 
Class zi
macro zi.GetLen { mov eax,[zi.len] }

Class zi
macro zi.GetLen2 b {
mov eax,[zi.len] 
Call b
}
    

Or do more complex call:
Code:
mov eax,[zi.VTBL]
push zi
call [eax+interface.GetLen]
    
Post 21 Aug 2020, 08:27
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
macros hides from programmer nature of operations.
I would prefer to read code
Code:
mov eax,[zi.len] ; I could see zi is structure, len its field    

against to read less intuitive
Code:
zi.GetLen ; but when I see this I have to find where macro that defined that, that macro could be nested in another macro, so answer could be not so trivial    


reading is suffer. preprocessor resources are suffer.
advantage? auto initialization\release - thou could provide these in includes & manualy use them no needance in building wrapper around of it all.

In assembly more significant how exactly some value passed to class - via instruction or via procedure to see what exactly there happend. Class wrapping hide this difference, and hides many other significant things.
Post 21 Aug 2020, 09:13
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
Quote:

mov eax,[zi.len]

Its for simple example.
In real i put in macro many asm commands.
Not comfortable all time write hands 20 asm commands in many places of code.

And programer implement and change macro and all changed in code.
Its big plus.

If program very small, i agree no needed class.
But if write compiler like Fasmw(160 kilobytes), class\macros could be very helpful.
Post 21 Aug 2020, 09:34
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 807
Location: Belarus
DimonSoft
Roman wrote:
I read about calss c++ that:
Class this is struct. First Vtbl(pointer to list class functions) and data.

Code:
class Object
{
int a,b;
public:
void GetRekt();
void Spawn();
};
    

Struct Object look:
Code:
Vtbl dd pFuns ;i think c++ create interface for pFuns offset.
      a dd 0
      b dd 0
pFuns dd GetRekt,Spawn
    

Interface Object,\
GetRekt,Spawn

Note that there’s no need to put non-virtual methods into VTable.
Post 21 Aug 2020, 10:04
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman


Last edited by Roman on 21 Aug 2020, 18:47; edited 2 times in total
Post 21 Aug 2020, 10:30
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 568
Location: Russian Federation, Sochi
ProMiNick
Роман, отсылка к классам Си++ лишняя.
То что у тебя реализоване - если тебе удобно, то почему бы и нет.
Куски которые лично удобно в макросы - всегда удобно.
Я же предпочитаю общие решения, поэтому мне классы не нравятся.
П.С. на видео комменты в руглише, фасм позволяет комментить на русском, ну а если на английском, то не английскими буквами же русские слова писать, по английски и комментировать.
А если классы на фасме интересуют посмотри фреш ИДЕ.
Post 21 Aug 2020, 12:52
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
Да класс иногда нужен когда пишешь редакторы для 3д игр.
И класс для 3д игр тоже облегчает жизнь.
Честно говоря пока не знаю насколько будет полезен и нужен в Fasm++ класс.

Quote:
А если классы на фасме интересуют посмотри фреш ИДЕ.

Не знал что в фреш ИДЕ есть классы.
А есть ли примеры классов или видео , как они сделаны в Fresh IDE ?
Post 21 Aug 2020, 13:28
View user's profile Send private message 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.