pioasm: support set x -1

Open Beginner friendly
#3,205 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@Firat17aze is already working on this.

Since Oct 13, 2026.

  • #3257 by @Firat17aze — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp

Research direction

Start in tools/pioasm/pio_assembler.cpp at instr_set::raw_encode. Trace how the resolved value and destination are encoded, especially for x, y, pins, and pindirs. Done means set x/y with -1 produces the equivalent inverted null move, while other destinations retain validation and the updated error message.

Written by the indexing model from the issue text.

Description

pioasm

Sometimes, it could be convenient when set x, -1 could also generate mov x, ~null (especially when -1 is a calculated value like (n-1 << 25 >> 25)). Not for pins and pindirs (different pin mappings) but for x and y:

diff --git tools/pioasm/pio_assembler.cpp tools/pioasm/pio_assembler.cpp
index a36854b2..5de3d972 100644
--- tools/pioasm/pio_assembler.cpp
+++ tools/pioasm/pio_assembler.cpp
@@ -385,8 +385,12 @@ raw_encoding instr_out::raw_encode(program& program) {

 raw_encoding instr_set::raw_encode(program& program) {
     int v = value->resolve(program);
+    if (v == ~0 && (dest == in_out_set::in_out_set_x || dest == in_out_set::in_out_set_y)) {
+        return {inst_type::mov, (uint) dest, (uint) mov::null | ((uint) mov_op::invert << 3u)};
+    }
+
     if (v < 0 || v > 31) {
-        throw syntax_error(value->location, "'set' bit count must be >= 0 and <= 31");
+        throw syntax_error(value->location, "'set' value must be >= 0 and <= 31 (or -1 for x and y)");
     }
     return {inst_type::set, (uint) dest, (uint) v};
 }
Dominant language
C
Stars
5k
Forks
1.3k
Avg merge
12d 19h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/pico-sdk

All issues in raspberrypi/pico-sdk

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.