flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 17 Aug 2011, 18:23
I'm not clear upon what you mean by "relocate CS and EIP saved to stack" but I am going to assume that you want to free the parameters upon return from the call. Generally there are two ways to approach it. 1) caller frees the parameters (C calling standard) and 2) callee frees the parameters (STDCALL calling standard). There are lots of posts already here about how these standards work at the assembly level. Remember that the search function is your friend.
Moving to main, this should not be in the heap |
|||
![]() |
|
AsmGuru62 18 Aug 2011, 13:24
Put the parameters into a structure and pass the address to it in a register. Same as stack, but no cleanup required.
|
|||
![]() |
|
vid 18 Aug 2011, 13:28
In order to do that, he should learn the proper method using stack first.
|
|||
![]() |
|
AsmGuru62 18 Aug 2011, 16:44
Oh!... I see... coding police arrived!
![]() Ok, I'll be good. When you call a procedure - parameters are PUSH-ed into stack: Code: push 1 push 2 push 3 call function If you compile that code and run it in debugger - you can stop just after the CALL instruction and you are on a first instruction inside the function. Take a look at the stack memory - at the very top it will be your return address. And then you will see values 3,2,1 - these are your parameters. If you push them in a reverse order - then they will show up as 1,2,3 in natural order. Now, to release the parameters all needs to be done is supply a RET instruction with a number of BYTES which taken by parameters, like so: function: ... RET 3*4 ; <-- 4 bytes per each of 3 parameters When function returns - the stack will be as BEFORE you pushed first parameter. All that is seen in debugger very well. |
|||
![]() |
|
edfed 19 Aug 2011, 04:05
you can pass parameters with predifened structures.
only ONE pointer is needed, and this pointer can be passed in another structure. double cool effet: never need to code push param1 param2 param3 etc... only MOV INDEX_REG,OBJECT is needed before to call the function, leave he stack as it is in the origin, a way to save the context of the previous code. architecture independant, the structure can be a file, useable by any CPU. but some not cool effects: this practice is a drug, and as is, it is a bad method for the coding police. nothing like registers can be passed, because need some mov. need at least one entry point in the structure tree. and is a little slower than stack. since i "found" this way to do, i only code like this, and i can spend an entire coding session without writing any asm instruction, all is in the structure. |
|||
![]() |
|
vid 19 Aug 2011, 09:42
edfed: you can also fill stack with MOVs, you don't have to allocate anything (like you have to with the object), stack memory is already cached
|
|||
![]() |
|
edfed 19 Aug 2011, 13:41
yep, maybe one day, i will use the stack segment to contain predifined objects.
the problem with stack is really the dynamic aspect, stack is always used for push/pop call ret, and then, it will insert various adresses between objects. that is a problem if you want to manage a big object list as a file. |
|||
![]() |
|
AsmGuru62 19 Aug 2011, 13:57
edfed: with a structure in some cases it is re-usable: fill it once, put the address into say, ESI, and then call diffreent functions - do not modify ESI, just functions may modify members of structure. Very smart and fast!
And now you got C++ in action! Neat! |
|||
![]() |
|
vid 19 Aug 2011, 15:35
edfed: Also if you mean "object" in proper sense, not simply as a structure holding parameters for particular call, then you have a problem with recursion. Especially with your predefined objects.
|
|||
![]() |
|
edfed 23 Aug 2011, 18:59
vid:
the reccursion problem is only when you code something reccursive, or when you do something with dynamic object linkibng (create pointers in the structures) in both case, the problem is solvable by a good attention of what is done. in pure asm, reccursion too is a problem, if you code something like... this: call this you have reccursion. especially if there is no exit condition test before the call. the only way to don't have reccurison problem is to test the code before to say it works. if you don't do dynamic pointer creation, the reccursion is close to impossible, because everything is defined by the coder, and the coder will not think reccursion, but sequences. AsmGuru62: modifying the datas is simple, and using the same structure for multiples function ids not a problem. some functions use other subfunctions, and of course, without data change. just and evolution, or nesting. Code: object dd 0,1,2,3 mov eax,object call trick trick: call .trick1 call trick1 ret .trick1: call trick1 ret trick1: ret |
|||
![]() |
|
FrozenKnight 25 Aug 2011, 13:54
This question is the same as asking; Where can i store information other than in registers?
You can use the stack, program memory, any static memory, dynamic allocated memory, files on disk, memory mapped file, SMC (Self Modifying Code, my favoret when speed isn't an issue) etc... So, just about anywhere. This isn't C/C++/Java/etc... where your options are limited. This is assembly you can do what ever you want. However, the commonly accepted method is to use the stack. For other ideas check out the Wikipedia article http://en.wikipedia.org/wiki/Calling_convention, be sure to go into the section for x86 it's more detailed for this architecture. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.