I wrote a macro at the beginning of a program, so that I can use it in the 'main' routine. Does anyone know how (where) the assembler allocates space in the program memory for a macro?
Basically the structure of my program is as follows
Code:
; Variable definitions here
Foo macro x,y
;....
endm
org 0x000
goto main
org 0x004
; ISR
main:
Foo A,B
; remaining code here
end
I wrote a macro at the beginning of a program, so that I can use it in the 'main' routine. Does anyone know how (where) the assembler allocates space in the program memory for a macro?
If that language is anything like C, then the macro itself never gets allocated, per se. But space for its code gets allocated once every time it's called.
In C, a preprocessor goes over the code before handing it to the compiler, and the preprocessor is what handles the macros. Once a macro has been defined, the preprocessor replaces all instances where the macro is called with the code from the macro definition. The resulting text (with other changes too) is passed to the compiler.
Same in assembler, the macro code is inserted everywhere it's used in the program - so depending what it does, how long it is, and if it's used a lot, it may make more sense to use a subroutine instead (which is only stored once).
Short answer, cumulatively at each location of instance.
Assuming the use of an IDE like MPLAB, you may also view the exploded view of the code from the Program memory window. Here you see how that macro is placed throughout the code and every opcode. Its very easy to accidentally do a computed jump into a macro instead of over it because your eyes see a single line or you miscalculate the actual number of instructions residing inside the macro. So I either replace long ones with a subroutine or make a dedicated macro include file having the length of each macro burned into my long term memory.
My favorites and only as to not taint the original language:
LOADF_F
MOVF_F
BANK1
BANK2
BANK3
BANK4
All 2 cycles long.