fn emit_state_store_u16(&mut self, field: Offset<u16>, value: u16) {
        // This operation is equivalent to this assembly:
        //
        //     mov word ptr [esi + <field>], <value>
        //
        // Here, we're using `MOV r/m16, imm16`, so our opcode is `0xC7`. To set the operand size to
        // 16 bits, we need to use the Operand size prefix byte `0x66` (otherwise, this would be a
        // 32-bit operation).
        //
        // Then we encode, again, the ModR/M byte just like we did in `emit_state_load_u8`: The
        // `MOD` field is set just like before, but the `REG` field is left at `0`, since we only
        // have a single addressed operand (the other one is an immediate). `R/M` is set to the
        // encoding of `esi` - `0b110`.
        //
        // The field offset is the next thing to encode, as a signed 32-bit displacement. Then
        // follows the immediate we want to store.

        let offset = field.bytes;
        assert!(offset < i32::MAX as usize);

        self.emit_raw(&[0x66, 0xC7, (0b10 << 6) | (0b110)]);
        self.code_buffer.write_i32::<LittleEndian>(offset as i32).unwrap();
        self.code_buffer.write_u16::<LittleEndian>(value).unwrap();
    }
/// Emits code to store a constant `u16` in a field inside the `ChipState`.
Emits code to store a constant `u16` in a field inside the `ChipState`.
Emits code to store a constant ` u16 ` in a field inside the ` ChipState ` .
fn emit_state_store_u16(&mut self, field: Offset<u16>, value: u16) {
        // This operation is equivalent to this assembly:
        //
        //     mov word ptr [esi + <field>], <value>
        //
        // Here, we're using `MOV r/m16, imm16`, so our opcode is `0xC7`. To set the operand size to
        // 16 bits, we need to use the Operand size prefix byte `0x66` (otherwise, this would be a
        // 32-bit operation).
        //
        // Then we encode, again, the ModR/M byte just like we did in `emit_state_load_u8`: The
        // `MOD` field is set just like before, but the `REG` field is left at `0`, since we only
        // have a single addressed operand (the other one is an immediate). `R/M` is set to the
        // encoding of `esi` - `0b110`.
        //
        // The field offset is the next thing to encode, as a signed 32-bit displacement. Then
        // follows the immediate we want to store.
        let offset = field.bytes;
        assert!(offset < i32::MAX as usize);
        self.emit_raw(&[0x66, 0xC7, (0b10 << 6) | (0b110)]);
        self.code_buffer.write_i32::<LittleEndian>(offset as i32).unwrap();
        self.code_buffer.write_u16::<LittleEndian>(value).unwrap();
    }
fn emit_state_store_u16 ( & mut self , field : Offset < u16 > , value : u16 ) { // This operation is equivalent to this assembly: // //     mov word ptr [esi + <field>], <value> // // Here, we're using `MOV r/m16, imm16`, so our opcode is `0xC7`. To set the operand size to // 16 bits, we need to use the Operand size prefix byte `0x66` (otherwise, this would be a // 32-bit operation). // // Then we encode, again, the ModR/M byte just like we did in `emit_state_load_u8`: The // `MOD` field is set just like before, but the `REG` field is left at `0`, since we only // have a single addressed operand (the other one is an immediate). `R/M` is set to the // encoding of `esi` - `0b110`. // // The field offset is the next thing to encode, as a signed 32-bit displacement. Then // follows the immediate we want to store. let offset = field . bytes ; assert ! ( offset i32 MAX as usize ) ; self . emit_raw ( & [ 0x66 , 0xC7 , ( 0b10 << 6 ) | ( 0b110 ) ] ) ; self . code_buffer . write_i32 :: < LittleEndian > ( offset as i32 ) . unwrap ( ) ; self . code_buffer . write_u16 :: < LittleEndian > ( value ) . unwrap ( ) ; }
Emits code to store a constant `u16` in a field inside the `ChipState`.
Emits code to store a constant ` u16 ` in a field inside the ` ChipState ` .
&mut self
field
Offset<u16>
value
u16
&mut self
field
Offset<u16>
value
u16