Encoding
The bit-string instructions are format II instructions with opcode 0x1F: the first halfword is 011111 00000 sub(5), so the instruction is two bytes long and has no register operand in the encoding; the 5-bit field is the sub-opcode.
Sub-opcodes 0x04 to 0x07 and 0x10 to 0x1F are undefined (the Mednafen core raises the invalid-opcode exception for them): the decoder shows them as illegal.
Bit 3 of the sub-opcode separates the two kinds: set means a bitwise operation between two strings, clear means a search.
The operand registers
The operands are in fixed registers, which is why r26 to r30 are set aside by the compilers. The roles below are those of the Beetle VB (Mednafen) core, which executes these instructions (bstr_subop and Do_BSTR_Search in its v810_cpu.cpp); an earlier version of this page gave r26 and r28 the other way round, from memory, and was wrong.
| Register | Holds |
|---|---|
r30 | the word address of the source string |
r29 | the word address of the destination string (for a search: a count of the bits skipped, which the search adds to) |
r28 | the length of the string in bits |
r27 | the bit offset of the source within its word |
r26 | the bit offset of the destination within its word |
The viewer lists r26 to r30 as read and written by the bitwise operations, and r27 r28 r29 r30 as read and written by a search; the instruction updates them as it goes and can be interrupted and restarted. The core adds clock counts per 16-bit half-word of memory touched; they are not listed here.
The instructions
| Mnemonic | Sub-opcode | Operation |
|---|---|---|
SCH0BSU | 0x00 | Search the bit string upward (towards higher addresses) for a 0 bit |
SCH0BSD | 0x01 | Search downward for a 0 bit |
SCH1BSU | 0x02 | Search upward for a 1 bit |
SCH1BSD | 0x03 | Search downward for a 1 bit |
ORBSU | 0x08 | destination = destination OR source |
ANDBSU | 0x09 | destination = destination AND source |
XORBSU | 0x0A | destination = destination XOR source |
MOVBSU | 0x0B | destination = source (copy) |
ORNBSU | 0x0C | destination = destination OR NOT source |
ANDNBSU | 0x0D | destination = destination AND NOT source |
XORNBSU | 0x0E | destination = destination XOR NOT source |
NOTBSU | 0x0F | destination = NOT source |
The operations run upward from the given bit offsets. The Mednafen source as read names the search direction by bit 0 of the sub-opcode (set: downward) and the bit searched for by bit 1 (set: a 1 bit). A search sets the Z flag (the core: Z = 0 when it found the bit, Z = 1 when the length ran out without one); the bitwise operations change no flag, so the decoder lists Z for the four searches and nothing for the rest.
Not described
See the status page: the register roles and the search flag above come from one emulator core (Beetle VB, read and compared in scripts/v810/beetle-compare.mjs), not from the NEC manual; the clock counts are not listed.