yes, macro arguments are text-substituted before the macro line is parsed, evaluated and assembled.
So `ld a, arg1` will become `ld a, (iBlue + iYellow)` and that will access memory from address #31 (ROM).
To avoid the similar issues like C macros have, you want to use macro arguments more like:
`ld a, +(arg1)` -> `ld a, +((iBlue + iYellow))` -> `ld a,#31`
Having parentheses around arguments in expressions helps to avoid stuff like:
BTW when in doubt, try listing (--lst --lstlab). You may see the macro lines somewhat substituted there, quick example trying to mimic your question:Код:macro m1 arg1, arg2 ld a, arg1 * arg2 ld a, +(arg1) * (arg2) endm m1 4<<2, 1+2 ; -> ; ld a, 4<<2*1+2 -> ld a, #40 ; 4 << (2*1+2) -> 4 << 4 -> 64 ; ld a, +(4<<2)*(1+2) -> ld a, #30 ; 16 * 3 -> 48
does produce this when using stdin as input and --msg=lst option:Код:macro m1 arg1, arg2 ld a, arg1 ld a, +(arg1) endm iBlue = %00000001 pYellow = %00110000 m1 (iBlue + pYellow), 123 ; btw "=" are not constants but "variables" or DEFL, so you can still modify them later, constants are EQU iBlue = %00000010 ; check next result m1 (iBlue + pYellow), 123
So by reading the listing file you have chance to spot unexpected bytes/instructions or evaluation results.Код:$ sjasmplus --msg=lst - macro m1 arg1, arg2 ld a, arg1 ld a, +(arg1) endm iBlue = %00000001 pYellow = %00110000 m1 (iBlue + pYellow), 123 ; btw "=" are not constants but "variables" or DEFL, so you can still modify them later, constants are EQU iBlue = %00000010 ; check next result m1 (iBlue + pYellow), 123 # file opened: <stdin> 1 0000 macro m1 arg1, arg2 2 0000 ~ ld a, arg1 3 0000 ~ ld a, +(arg1) 4 0000 endm 5 0000 iBlue = %00000001 6 0000 pYellow = %00110000 7 0000 m1 (iBlue + pYellow), 123 7 0000 3A 31 00 > ld a, (iBlue + pYellow) 7 0003 3E 31 > ld a, +((iBlue + pYellow)) 8 0005 ; btw "=" are not constants but "variables" or DEFL, so you can still modify them later, constants are EQU 9 0005 iBlue = %00000010 ; check next result 10 0005 m1 (iBlue + pYellow), 123 10 0005 3A 32 00 > ld a, (iBlue + pYellow) 10 0008 3E 32 > ld a, +((iBlue + pYellow)) 11 000A # file closed: <stdin>




Ответить с цитированием
Размещение рекламы на форуме способствует его дальнейшему развитию 
