-
Couldn't load subscription status.
- Fork 1.1k
Description
I have a recommendation for a new pseudoinstruction, and explanation on why it's so useful.
Is this the right depot to file the issue in?
If yes, then I will change the title of the issue to:
Request for new pseudoinstruction: dec X / dec Y
Assembler Syntax
dec <target>, where <target> is either X or Y
For target X:
- Assembly equivalent:
jmp (x--), <uniquelabel> <uniquelabel>:
- 16-byte opcode:
0b_000_ddddd_010_aaaaadddddrepresents the delay/side-set bitsaaaaarepresents the encoded address to jump to
Edge cases
Normally, the dec <target> pseudoinstruction encodes to a jmp to the next instruction in the program.
Therefore, pioasm would need to handle the following two edges cases:
- Where the pseudoinstruction precedes a
.wrapdirective -- encode thejmpaddress to the.wraptarget - Where the pseudoinstruction is the last instruction of the program -- encode the
jmpaddress to the.wraptarget
Why do this?
Two reasons: First, to increase awareness of how to do this. Secondly, to avoid incorrectly written implementations.
When looking for how to modify the data in a register, a user will first look at the set and mov instructions. The impression given is that only negation and reversing the bits are available. However, decrement is a supported atomic operation!
There's also the problem of buggy attempts, where a person initially has an unconditional jmp, needs to decrement the register at the same time, and converts that to a jmp (x--) label ... thus introducing a bug, because if the register value pre-execution was zero, the jump will not happen. (yes, real world story)