DCPU-16 icon indicating copy to clipboard operation
DCPU-16 copied to clipboard

Macros and label resolution

Open jabr opened this issue 12 years ago • 2 comments

In the example below, the label end passed to the braf macro is not resolved (it becomes zero) in the assembled output. It should behave like the macro-expanded line following it.

#macro brab(label) {
   sub PC, 2+.-label
}

#macro braf(label) {
   add PC, label-(2+.)
}

:start

dat 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

brab start
sub PC, 2+.+start
braf end
add PC, end-(2+.)

dat 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

:end

dat 0

jabr avatar May 01 '12 05:05 jabr

To clarify the code example above:

brab start ; works like the following line
sub PC, 2+.+start

braf end ; broken -- generates a ADD PC, 0 (next word literal 0)
add PC, end-(2+.) ; works as expected

jabr avatar May 01 '12 05:05 jabr

i think i might have fixed this in my macro branch that just got merged. can you try it now?

robey avatar May 22 '12 09:05 robey