On 2016-04-01 23:44, Mouse wrote:
But half the point in the original example code was that you can have any instruction there,Not quite - only a single-word instruction. Lots of PDP-11 instructions are (or at least can be) two words long; while my PDP-11 is a bit weak, I think some can even be three words long.
Oh, definitely. PDP-11 instructions can be even longer. Not sure where the PDP-11 came into this, but the PDP-11, as opposed to the VAX, do give the size of the full instruction in the first word.
Rhialtos original post used the 6502 as an example. And the point was to avoid doing a jump, which takes two or three byets, by instead putting in an instruction which will "eat" the next instruction, thus skipping it.
which then can be skipped by this clever "prefix". This general approach will not work on a VAX.True; it is far more restricted on the VAX. There _are_ single-byte instructions, but not many. The list I have at readiest hand shows eight, of which three are kernel-only (HALT, LDPCTX, SVPCTX) and none of the rest (BPT, NOP, REI, RET, RSB) strike as very useful in this trick - all but NOP provoke some form of unusual control flow.
I think you are missing the point. It's not about the number of operands of the instruction, it's about the encoding of instruction and the encoding of operands.
Let's say that you have a MOVL (R2),(R3), and you might want to skip it, so you need an instruction to precede this instruction sequence.
Now, a MOVL (R2),(R3) will in fact take three bytes. The MOVL is one byte, the (R2) is one byte, and (R3) is another byte.
Now, what instruction would you prefix this, in order to eat those three bytes? No matter what it is, this prefix instruction that should eat that sequence will then unavoidably interpret the MOVL instead as an argument. If you look at the opcode for MOVL, what is that when interpreted as an argument? It will (hopefully) be something that don't consume more than two additional bytes, because then you loose. But if it uses less than two bytes, then you need the instruction to consume the next one or two bytes. But the big problem is the MOVL itself, that will be interpreted as an argument. Now, every opcode have some corresponding interpretation as an argument, and this will severely limit which instructions you can "eat", as their interpretation as arguments often will mess up the idea of just eating up the next instruction.
On a machine where the total length of the instruction is decided by the first byte are much easier to do this with, since you can easily eat any instruction by just prefixing it with something that eats that many bytes. But this requires that opcodes give you the total length of the instruction. This is absolutely not true for the VAX, and partially also not true for the PDP-11.
In addition, for the PDP-11, this whole construct is of limited use, as a branch is the shortest instruction you can have anyway, so you cannot actually save any bytes in general by such a eating instruction prefix in the first place. The branch will be just as cheap memory wise. The example Paul Koning posted is sortof a special case, in that you want to accomplish two things, and that specific piece of code does both things (clearing the carry, along with skipping the setting of the carry).
Johnny -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: bqt%softjar.se@localhost || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol