Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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...
 
e said:
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.

New Articles From Microcontroller Tips

Back
Top