hey guys
i was just wondering wat is good to use??? a macro or a proc ,so as to make an efficient exe with smaller size and faster execution.coz..............

Procedure is located at some specific address in memory, and if you use the same procedure 100 times, the CPU will transfer control to this part of the memory. The control will be returned back to the program by RET instruction. The stack is used to keep the return address. The CALL instruction takes about 3 bytes, so the size of the output executable file grows very insignificantly, no matter how many time the procedure is used.

Macro is expanded directly in program's code. So if you use the same macro 100 times, the compiler expands the macro 100 times, making the output executable file larger and larger, each time all instructions of a macro are inserted.
Posted on 2004-10-07 15:26:37 by nickdigital
My understanding is that procs are slower to execute, because of all the pushing, and the call and ret...making it really a tradeoff between speed and size.

Today's computers are so fast though that in most cases I wouldn't think you'd even notice the slight speed gain from using a macro. I code procs until things become slow enough that I notice, then I consider converting to a macro.
Posted on 2004-10-07 15:35:15 by sirchess
It mostly depends on your code.

- ...You are hunting for execution cycles in a routine (i.e. encryption) and there is a repeated part of code. It's obvious that implementing macro is a good idea, as it will save you some typing. Procedure will be useless here because the call/ret have very slow execution. Using macro will add to size of function, but remember that goal here is the speed, not the size.

- ...You want to make very small executable and speed doesn't matter alot. Then procedure will be a good idea for a frequently repeated block.

Of course all this depends on many other factors. Wrongly implementation of macro can be even slower than procedure. If you got variable parameters to pass and stuff to save so it wont get modified, you'll need to implement the same pushes/pops in macro.

I use macros only when the part of code is frequently repeated (it's a life saver in encryption routines) and the code doesn't need to accept any variable parameters. Procedures when there is a need for one. In any other cases pure code it is. Because that way I can play more carefully with registers. And no space/speed is lost.
Posted on 2004-10-07 17:00:33 by arafel