flat assembler
Message board for the users of flat assembler.
Index
> Main > How many instructions endorse the definition of a function |
Author |
|
a115433 16 Apr 2010, 09:18
number of instructions isnt property of function/macro.
so it can be infinite, and 0. |
|||
16 Apr 2010, 09:18 |
|
pete 16 Apr 2010, 09:35
Probably my question was unclear. If, for instance i have a set of instructions that get repeatedly executed through the runtime of a program, i want to optimize the program to store the same set of instructions as seldom as possible. This forces me to use functions or procedures. But of course i want the program to run as fast as possible. So when i call a procedure inside my program very often, but this procedure consists of only four instructions, i am thinking of converting this procedure into a macro instead, because the jumping around in the memory that comes with procedures probably isn't worth the four instructions.
So what i am interested in is, how many instructions should a procedure at least consist of, so that the memory jumps (through call and return) are endorsed? |
|||
16 Apr 2010, 09:35 |
|
edfed 16 Apr 2010, 10:43
4 instructions? ok, lets go for a function, then, you will have many more flexibility during software evolution.
i have a fucntion with 4 instructions, including ret. Code: asm: .call=0 .func=4 .op1=8 .op2=12 .op3=16 .op4=20 .op5=24 .op6=28 .op7=32 .op8=36 cmp dword[esi+.func],0 je @f call near[esi+.func] @@: ret |
|||
16 Apr 2010, 10:43 |
|
pete 16 Apr 2010, 11:22
Thanks for the example edfed, but why do i gain flexibility during software evolution with a function?
|
|||
16 Apr 2010, 11:22 |
|
edfed 16 Apr 2010, 11:51
simple to explain.
a function, for example, put a picture. instead of puting pixel inside the picture function, you use putpixel subfunction, then, you just give X,Y and color to putpixel. then, if you change screen mode (320*200*8bpp to 1280*1024*32bpp), only putpixel function will change. if you want to draw line, you will use the same putpixcel function, draw a rectangle, draw a circle, draw a triangle, put text, etc... and all will use only one putpixel fucntion, then, mode switch will be easy. and if one day you use hardware acceleration, some complex putpixel queue will be good, or something like that. there are many other examples where a function is good. a function that have only 4 instruction can easy become fat, adding security tests, particular case, etc.. |
|||
16 Apr 2010, 11:51 |
|
pete 16 Apr 2010, 12:05
Well, thanks!
|
|||
16 Apr 2010, 12:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.