Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 16th May 2004, 02:05 PM   (permalink)
Default pic assembly - macro or subroutine???

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?
spyghost is offline  
Old 16th May 2004, 02:12 PM   (permalink)
Default

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 is offline  
Old 16th May 2004, 02:43 PM   (permalink)
Default

Quote:
Originally Posted by e
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 18th May 2004, 05:29 AM   (permalink)
Default

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.
donniedj is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 04:59 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker