flat assembler
Message board for the users of flat assembler.
Index
> Main > How does OOP concept works at assembly level? Goto page 1, 2 Next |
Author |
|
Teehee 15 Jul 2010, 13:06
?
_________________ Sorry if bad english. |
|||
15 Jul 2010, 13:06 |
|
edemko 15 Jul 2010, 13:40
Our lecturer said: "Control's properties are nob-hiden metods".
|
|||
15 Jul 2010, 13:40 |
|
vid 15 Jul 2010, 13:41
you have set of data structure declarations ("classes" in OOPspeak), and you have set of procedures ("methods") that work with these structures. Procedure always gets a pointer to structure in memory that it works with (instance of structure declaration, "class instance" or "object" in OOP) as an argument. Point is that these procedures never touch anything else besides the class they work with and supplied arguments. You try to create a procedure for anything that ever is done with the structure, and never touch its data members directly outside these procedures.
This way, you have a very clean interface to work with your data structures, with minimal side effects. There are some extra useful things this provides, but that is not so important now. Also see: http://x86asm.net/articles/oop-from-low-level-perspective/index.html (But note l am no longer happy with approach taken in this article, and it is unfinished) edit: link fixed Last edited by vid on 15 Jul 2010, 14:22; edited 1 time in total |
|||
15 Jul 2010, 13:41 |
|
edemko 15 Jul 2010, 13:44
i remember myself so happy i could change constant variable with a built-in-asm
though delphi allowed doing it too oop are the blocks you can sharpen with asm <vid>, dead link |
|||
15 Jul 2010, 13:44 |
|
revolution 15 Jul 2010, 13:46
edemko wrote: ... i could change constant variable ... |
|||
15 Jul 2010, 13:46 |
|
edemko 15 Jul 2010, 13:49
sure, missed
variable constant(fickle HLL as it can be changed |
|||
15 Jul 2010, 13:49 |
|
edemko 15 Jul 2010, 13:50
asm is stable, hll is fickle
EDIT: once Borland mentioned Objects were the hill now Bor-land is dead Bor, by the way, means pine forest |
|||
15 Jul 2010, 13:50 |
|
bitshifter 15 Jul 2010, 20:00
And it gets really gross once you start using virtual tables (yuk)
|
|||
15 Jul 2010, 20:00 |
|
Teehee 15 Jul 2010, 22:43
thanks guys.
|
|||
15 Jul 2010, 22:43 |
|
Tyler 16 Jul 2010, 02:38
gcc -S -masm=intel -o whateverexe whatevercpp.cpp
|
|||
16 Jul 2010, 02:38 |
|
Teehee 28 May 2011, 14:17
@Tyler, nice tip
i'm doing some tests using OOP (based on vid's link). Is my code below an inheritance example? Code: format PE CONSOLE include 'win32a.inc' entry _start section '.code' code readable executable _start: mov esi,ENEMY ; you can change to HERO mov ebx,[esi] ; load .type (CHARACTER) call dword[ebx+4] ; call char_walk(+4) or char_attack(+0) invoke ExitProcess,0 msg_walk db '%s walking',0 char_walk: lea ebx,[esi+4] cinvoke printf,msg_walk,ebx ret msg_attack db '%s attacking',0 char_attack: lea ebx,[esi+4] cinvoke printf,msg_attack,ebx ret section '.data' data readable writeable CHARACTER: .attack dd char_attack .walk dd char_walk HERO: .type dd CHARACTER .name db 'hero',0 ENEMY: .type dd CHARACTER .name db 'enemy',0 section '.idata' import data readable library kernel32,'kernel32.dll', msvcrt,'MSVCRT.DLL' import msvcrt,printf,'printf',scanf,'scanf' import kernel32,ExitProcess,'ExitProcess' Lets say i will need a N# of enemies. How do i create them? (equivalent to new ENEMY() in high-level) _________________ Sorry if bad english. |
|||
28 May 2011, 14:17 |
|
Tyler 28 May 2011, 17:48
You get(allocate/static store/wtf else) N ENEMY structures and call the ENEMY constructor (which you don't have, nor need, for now).
|
|||
28 May 2011, 17:48 |
|
Tyler 28 May 2011, 17:53
I prefer C, if you don't mind(IMO, it's more efficient for examples and usually trivial to translate):
Code: struct ENEMY{}; enemy_constructor(ENEMY *e) { // initialize e } int main() { ENEMY enemies[] = malloc(sizeof(ENEMY * N)); for(int i = 0;i < N;i++) enemy_constructor(&enemies[i]); // you now have N enemies return 0; } |
|||
28 May 2011, 17:53 |
|
Teehee 28 May 2011, 18:25
okay, i can understand that, but i don't know how to translate to asm.
|
|||
28 May 2011, 18:25 |
|
Teehee 28 May 2011, 18:39
Code: ENEMY: .size = $-ENEMY enemy_constructor: ret 4 _main: sub esp,ENEMY.size * N mov ecx, N @@: push [esp+ENEMY.size*ecx] call enemy_constructor dec ecx jnz @b ret maybe something like that? (i didnt compile it) but i have trouble when working with dynamic memory (malloc?), i mean, how to manage it. ( PS: how das malloc works? ) I think the most difficult i have is understand the dynamic/static memory, i mean, not teoricaly, but at practic. So i get confused when need to do arrays of unknow-size data. _________________ Sorry if bad english. |
|||
28 May 2011, 18:39 |
|
vid 28 May 2011, 19:03
I suggest to practice with malloc / free first, and only then move on to OOP.
|
|||
28 May 2011, 19:03 |
|
Teehee 28 May 2011, 19:05
in asm you mean? how can i do that?
|
|||
28 May 2011, 19:05 |
|
vid 28 May 2011, 19:39
Doesn't matter. If you don't wish to use malloc() from libc, you can call directly system API (eg. HeapAlloc in Windows, etc.). Without understanding dynamic memory well, you really shouldn't approach OOP.
|
|||
28 May 2011, 19:39 |
|
Teehee 28 May 2011, 19:46
well, i know that functions return a handle to the first memory place. And then i need to fill that memory space with my structures. But what if there is no more memory there anymore, i will need to realloc more and copy all the last data to the new handle, or i keep tha last buffer but use the new one?
|
|||
28 May 2011, 19:46 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.