I saw some old posts on this topic but no resolution.
Some people said that you can't pass 16-bit parameters to a Macro.
But you certainly can. Here are some examples that work:
; LOAD Z-REGISTER IMMEDIATE .MACRO LDZI LDI R30, LOW(@0) LDI R31, HIGH(@0) .ENDMACRO
LDZI ARRAY_START_ADDRESS ; ARRAY_START_ADDRESS IS AN ARRAY DECLARED IN DSEG. THIS WORKS FINE
.EQU PHOTOCELL_QUIESCENT_VOLTAGE=1019 LDZI PHOTOCELL_QUIESCENT_VOLTAGE ; NOW WE ARE GETTING IT TO ACCEPT 16-BIT CONSTANTS DECLARED WITH AN .EQU AND IT WORKS FINE
So when the code in the .MACRO is LDI it seems to work fine with either 16-bit addresses passed as a parameter or 16-bit constants declared by an .EQU
It also allows you to pass the address of a label in your code, for example
RESUME1: ....SOME ASM CODE.... LDZI RESUME1 PUSHZ_BIGENDIAN
I use the above to push a return address on the stack when I want a subroutine call to return to different places
depending on the outcome of a calculation, and it works fine.
So it seems we can pass 16-bit constants, RAM variable addresses or code labels fine.
But this does not work:
.MACRO SUBTRACT16 SBI R22,LOW(@0) SBCI R23,HIGH(@0) .ENDMACRO
.EQU PHOTOCELL_QUIESCENT_VOLTAGE=1017 SUBTRACT16 PHOTOCELL_QUIESECENT_VOLTAGE
But this does work:
.MACRO SUBTRACT16 LDI R30,LOW(@0) LDI R31,HIGH(@0) SUB R22,R30 SBC R23,R31 .ENDMACRO
so my question is: Why does it work when the .MACRO receiving the parameter is just doing an LDI with it
and does not work if it is using the passed parameter as an immediate with some other instruction that would normally
happily accept such immediate constants outside of the .MACRO?
What are the rules and where can I find them written down?