![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| hi, macros and subroutines have some similarity, right? but there arises this question: - should i use macro or subroutine? are there pointers really for using one over the other? or is it just a matter of personal preference? | |
| |
| | (permalink) |
| A macro will shove a chunk of code in everytime you use it, so if its a long macro your code will grow quickly. I dont like using macros over a few lines (maybe 2 or 3), id rather use subroutines for anything over that length. Macros are nice to say things like "led_on" instead of "bcf PORTA,2" or something like that, and since the macro is only one line it makes no difference... | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| I concur with both above. Macros are short and subroutines are long. My best and most utilized of very few macros are: MOVF_F REGISTER1, REGISTER 2 LOADF REGISTER, LITERAL SWAPF REGISTER1, REGISTER 2 Personally, the least macros the better and the purer the assembly code. I believe that a major portion of Microchips popularity is attributed to their 35 instruction set, a set that actually consumes only 5 to 10 different instructions in a program. Logically, macros jeoperdize computed goto(s) because you may forget how much space the nearby macros actually consume. | |
| |