Search code examples
luavirtual-machineopcodes

What's the difference between normal opcodes and opcodes with their MSB set?


What's the difference between normal opcodes and opcodes with their MSB (Most Significant Bit) set?

Example:

0036  5E000001           [4] return     1   2
003A  1E008000           [5] return     0   1

The first opcode (0x5E/1011110) has its MSB set and the second opcode (0x1E/0011110) hasn't.

Edit: Corrected 'byte' to 'bit', duh.


Solution

  • After some googling, I found a header of the Lua source (lopcodes.h) explaining the instruction format a bit better.

    It looks like it's wrong to read the opcode as a byte, it should be read as 6 bits:

    All instructions have an opcode in the first 6 bits.
    Instructions can have the following fields:
    `A' : 8 bits
    `B' : 9 bits
    `C' : 9 bits
    `Bx' : 18 bits (`B' and `C' together)
    `sBx' : signed Bx