diff --git a/src/asm/macro.c b/src/asm/macro.c index e478d06e..b6220490 100644 --- a/src/asm/macro.c +++ b/src/asm/macro.c @@ -168,12 +168,12 @@ void macro_ShiftCurrentArgs(int32_t count) { if (!macroArgs) { error("Cannot shift macro arguments outside of a macro\n"); - } else if (count < 0) { - error("Cannot shift arguments by negative amount %" PRId32 "\n", count); } else if (macroArgs->shift < macroArgs->nbArgs) { macroArgs->shift += count; if (macroArgs->shift > macroArgs->nbArgs) macroArgs->shift = macroArgs->nbArgs; + else if (macroArgs->shift < 0) + macroArgs->shift = 0; } } diff --git a/src/asm/rgbasm.5 b/src/asm/rgbasm.5 index 04402096..0e07750d 100644 --- a/src/asm/rgbasm.5 +++ b/src/asm/rgbasm.5 @@ -1487,6 +1487,7 @@ This is the only way of accessing the value of arguments from 10 to 256. .Pp .Ic SHIFT can optionally be given an integer parameter, and will apply the above shifting that number of times. +A negative parameter will shift the arguments in reverse. .Ss Printing things during assembly The .Ic PRINT diff --git a/test/asm/shift-negative.asm b/test/asm/shift-negative.asm index 4d41f406..d99d5eef 100644 --- a/test/asm/shift-negative.asm +++ b/test/asm/shift-negative.asm @@ -1,4 +1,16 @@ +reverse: MACRO + for i, _NARG +i = _NARG - i - 1 + shift i + println \1 + shift -i + endr +ENDM + + reverse $1, $2, $3 + m: MACRO + shift 2 shift -3 ENDM m diff --git a/test/asm/shift-negative.err b/test/asm/shift-negative.err index 367f2e01..e69de29b 100644 --- a/test/asm/shift-negative.err +++ b/test/asm/shift-negative.err @@ -1,3 +0,0 @@ -ERROR: shift-negative.asm(4) -> shift-negative.asm::m(2): - Cannot shift arguments by negative amount -3 -error: Assembly aborted (1 errors)! diff --git a/test/asm/shift-negative.out b/test/asm/shift-negative.out index e69de29b..edc69c9c 100644 --- a/test/asm/shift-negative.out +++ b/test/asm/shift-negative.out @@ -0,0 +1,3 @@ +$3 +$2 +$1