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.
Whats the difference? Are macros only for high-level languages? If no, then how do you use a macro in PIC assembly language. Are these two different names for the same thing?
A macro is just short hand. A subrountine is "called."
Subroutines can save memory by reducing repeated code, but take more time because you have to push arguments and return addresses, and push the result and pop back.
A macro is the code literally inserted where you put it. It doesn't save any memory but is as fast as the bit of code you put there, saves typing, and is easier to read.
For example, if I define a macro
#define TOGGLE_PIN1 PORTD.1=0;PORTD.1=1;PORTD.1=0
and put it in my code like so
putsf("I'm going to toggle PIN1 now");
TOGGLE_PIN1;
putsf("PIN1 was toggled");
it would be exactly the same, to the processor, as
putsf("I'm going to toggle PIN1 now");
PORTD.1=0;PORTD.1=1;PORTD.1=0;
putsf("PIN1 was toggled");
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.