[SOLVED]"missing" bytecode 0x81?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

[SOLVED]"missing" bytecode 0x81?

Post by jickster » Wed Oct 25, 2017 6:45 pm

This is main.py

Code: Select all

led = pyb.LED(1)
This is the frozen main.mpy

Code: Select all

// frozen bytecode for file main.py, scope main_<module>
STATIC const byte bytecode_data_main__lt_module_gt_[30] = {
    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
    MP_QSTR__lt_module_gt_ & 0xff, MP_QSTR__lt_module_gt_ >> 8,
    MP_QSTR_main_dot_py & 0xff, MP_QSTR_main_dot_py >> 8,
    0x61, 0x20, 0x00, 0x00, 0xff,
    0x1b, MP_QSTR_pyb & 0xff, MP_QSTR_pyb >> 8,
    0x1e, MP_QSTR_LED & 0xff, MP_QSTR_LED >> 8,
    0x81, 
    0x66, 0x01, 
    0x24, MP_QSTR_led & 0xff, MP_QSTR_led >> 8,
    0x11, 
    0x5b, 
};
What is bytecode 0x81?
It doesn't appear to be consumed by 0x1e (load method)

Code: Select all

case (0x1e): {
                    ;
                    qstr qst = ip[0] | ip[1] << 8; ip += 2;;
                    mp_load_method(*sp, qst, sp);
                    sp += 1;
                    break;
                }
It doesn't appear in bc0.h
Last edited by jickster on Wed Nov 01, 2017 5:57 pm, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: "missing" bytecode 0x81?

Post by pythoncoder » Thu Oct 26, 2017 7:20 am

bc0.h has

Code: Select all

#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64)
I think this means that immediate values in a 6 bit range are added to the bytecode so that bytecodes 0x70-0xaf are emitted. So bytecode 0x81 has an immediate value of 17 (base 10) encoded.
Peter Hinch
Index to my micropython libraries.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: "missing" bytecode 0x81?

Post by jickster » Thu Oct 26, 2017 3:26 pm

pythoncoder wrote:
Thu Oct 26, 2017 7:20 am
bc0.h has

Code: Select all

#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64)
I think this means that immediate values in a 6 bit range are added to the bytecode so that bytecodes 0x70-0xaf are emitted. So bytecode 0x81 has an immediate value of 17 (base 10) encoded.
What is immediate value?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: "missing" bytecode 0x81?

Post by pythoncoder » Fri Oct 27, 2017 5:38 am

Many machine instruction sets include instructions with an "immediate" value embedded into the opcode. Usually the immediate value is an integer with a limited range. It's a fast way to load a register with a small constant value. My guess is that this bytecode does something similar with values in a 6 bit range. So, in an entirely fictional assembly language

Code: Select all

mov r0, 5
causes the assembler to emit the machine word 5 + <opcode for mov r0, x>
Peter Hinch
Index to my micropython libraries.

Post Reply