pic assembly - macro or subroutine???

Status
Not open for further replies.

spyghost

New Member
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?
 
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...
 

I agree, use a subroutine for anything you use more than once, unless it is exceptionally short.
 
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…