Hi all, I've got a couple of questions: 1) I am going tutorial-by-tutorial, and have stopped at the mouse-input as I am wanting to convert some things into PROCS.. how would I make a, say, SetFont proc in a different file and include(?) it in so I can do some data hiding? Macros are wonderful but as I understand it add to the bloating of a program. 2) How safe would it be to throw stuff into PROCS.. I mean, making sure all register's integrities are not compromised? I would love to invoke all sorts of stuff and build some procs of my own, and what if I invoke three or four procs in a row and trash a register that is needed elsewhere later? Thank you for your support :)~
Posted on 2001-07-05 09:24:00 by 3DWannaBe
There are two ways to make reusable code: 1) Write it as a .asm file, and simply type
"include \myAsm\stuff\blah.asm"
in the file. The include directive makes the assembler treat it as if it were part of the file it is included in. This is a simple way of adding things to a file. 2) Write the .asm file, put it together with a whole bunch of other .asm files and create a lib out of them all. This is how the MASM32 lib is made. Check out the relevent batch files in the MASM32 pack. As for using macros, they are not really designed for a whole proc, more for simple but repetative tasks. Common examples are things such as loading an RGB value into a register, or a C style "return (int)x" statement. Macros do not cause "bloat" unless they are misused. They make code more readable by replacing several statements with one command. The compiler will expand the macro to the exact code specified at compile time. As for your second question: In Win32 the registers ebx, esi, and edi are all expected to be "left alone". They can be used in your code, but must be restored afterwards, this is usaully achieved with push's and pop's. When specifying your proc you can use the "USES" directive, and it will take care of the pushing and poping for you, and so keep your code a little cleaner. You cannot expect the registers eax, ecx, and edx to hold a particular value after a proc, unless it is specified by the procedure, or you have written it specifically with that feature in mind. All the API will preserve ebx, esi, and edi. They usually return data in eax (but sometimes return data to some area of memory specified when calling that function). The contents of the other three general use registers are not guaranteed to maintain their value, and anything they do return is not guaranteed in future releases of windows either! Mirno
Posted on 2001-07-05 10:24:00 by Mirno
Mirno, thank you for your expedient and concise reply :) I shall go forth and wreak havoc!
Posted on 2001-07-05 10:44:00 by 3DWannaBe