Instructions
Instructions are the basic building blocks of a PIO program. Each instruction corresponds to a single machine code that can be executed by the PIO state machine.
Function Notation
In the Method-Chain PIO Assembler, instructions are represented as member functions of the Program class. In C++'s formal syntax, they should be described as follows:
For more pragmatic notations, this page uses the following syntax to represent the instructions:
Instruction Modifiers
All instructions can be used with the following modifiers:
.side
Sets the value of side-set pins that start from the GPIO base pin specified by StateMachine::set_sideset_pins() or StateMachine::config_set_sideset_pins(). This modifier is only valid when the .side_set() directive is used. If the .side_set() directive comes with the .pindirs() modifier, the value specified by this modifier sets the direction of the pin, not the value on the pin.
.delay
An instruction is executed in a single cycle. When the .delay() modifier is used, the specified cycles are added to the execution time of the instruction.
List of Instructions
Below is a list of instructions available in the method-chain PIO assembler.
.jmp
Jump to the specified address or label.
Jump to the specified address or label if the value of register x is zero.
Jump to the specified address or label if the value of register x is not zero, and then decrement the value of register x.
Jump to the specified address or label if the value of register y is zero.
Jump to the specified address or label if the value of register y is not zero, and then decrement the value of register y.
Jump to the specified address or label if the value of register x is not equal to the value of register y.
Jump to the specified address or label if the GPIO pin specified by StateMachine::set_jmp_pin() is high.
Jump to the specified address or label if the output shift register (osr) is not empty.
.wait
Wait until the GPIO pin specified by index is low (0) or high (1). The index is the absolute GPIO pin number.
Wait until the GPIO pin specified by index is low (0) or high (1). The index is the relative index from the GPIO base pin specified by StateMachine::set_in_pins().
Wait until the IRQ specified by index is low (0) or high (1).
.in
The count bits from the GPIO pins specified by StateMachine::set_in_pins() or StateMachine::config_set_in_pins() are shifted into the isr.
The least significant count bits of the x register are shifted into the isr.
The least significant count bits of the y register are shifted into the isr.
The count bits of zeros are shifted into the isr.
The least significant count bits of the isr are shifted into the isr.
The least significant count bits of the osr are shifted into the isr.
.out
The count bits from the osr are shifted out to the GPIO pins specified by StateMachine::set_out_pins() or StateMachine::config_set_out_pins().
The count bits from the osr are shifted into the least significant bits of the x register. The most significant bits of the x register are filled with zeros.
The count bits from the osr are shifted into the least significant bits of the y register. The most significant bits of the y register are filled with zeros.
The value of the osr is shifted by count bits.
The count bits from the osr are shifted out to the pin direction control of the GPIO pins specified by StateMachine::set_out_pins() or StateMachine::config_set_out_pins().
The count bits from the osr are shifted into the least significant bits of the PC register. The most significant bits of the PC register are filled with zeros.
The count bits from the osr are shifted into the least significant bits of the isr. The most significant bits of the isr are filled with zeros.
The count bits from the osr are shifted into the least significant bits of the osr. The most significant bits of the osr are filled with zeros.
.push
Pushes the value of the isr to the RX FIFO. Clears the value of the isr after the push.
.push() instruction can be used with the following modifiers:
.iffull(): Pushes theisrvalue to the RX FIFO only whenisr's shift amount reaches the specified value..block(): Blocks the execution until the RX FIFO is ready to accept data..noblock(): Does not block the execution, even if the RX FIFO is not ready.
.pull
Pulls data from the TX FIFO to the osr.
.pull() instruction can be used with the following modifiers:
.ifempty(): Pulls data from the TX FIFO to theosronly when theosr's shift amount is zero..block(): Blocks the execution until there is data in the TX FIFO..noblock(): Does not block the execution, and sets theosrwith the value of the X when there is no data in the TX FIFO.
.mov
Move data from src to the x register.
Move data from src to the y register.
Execute the instruction specified by src.
Move data from src to the program counter, meaning an unconditional jump to the address specified by src.
Move data from src to the isr.
Move data from src to the osr.
The src can be pins, x, y, null, status, isr, or osr. It can also be applied with the following operators:
!srcor~src: Bitwise complement of the value ofsrcis moved todst. e.g. if the value ofsrcis0b00010011'00000000'10101010'00111100, the value moved from!srcwill be0b11101100'11111111'01010101'11000011.::src: Bit revese of the value ofsrcis moved todst. e.g. if the value ofsrcis0b00010011'00000000'10101010'00111100, the value moved from::srcwill be0b00111100'01010101'00000000'11001000.
If the PIO version is 2.0 or above, the following variants of the .mov instruction are also available for moving data between the shift registers and the FIFOs.