1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Instruction boundaries in a big-endian H8 instruction stream.
//!
//! Length recognition covers the legacy opcode maps and H8SX §2.4 rows.
//! H8SX rules are generated from checked manual facts with explicit operand
//! constraints. Semantic decoding remains narrower than length recognition.
pub use disassemble_insn;
pub use ;
pub use ;
pub use complex_relative as sx_complex_relative;
use crate::;
/// Maximum length, in bytes, of an H8 instruction across the supported cores.
///
/// H8SX REJ09B0102 §2.4 Table 2.2 has at most three 16-bit opcode words
/// and two 32-bit operand extensions (6 + 8 = 14 bytes). Its ADD.B
/// `@(d:32,ERs),@(d:32,ERd)` row attains this bound. Earlier cores have
/// shorter instruction-code tables (H8S REJ09B0139 §2.4 Table 2.2).
pub const MAX_INSN_LEN: usize = 14;
/// Returns the length of the first complete, recognized instruction in `bytes`.
///
/// Returns `None` for a truncated instruction, an undefined encoding, an
/// unsupported target/mode pair, or a pattern outside the implemented manual
/// row grammar. Trailing bytes are ignored. This checks encoding and
/// length, not whether executing the instruction is safe in the current state.
///
/// Unlike Thumb, H8 instruction length cannot always be determined from the
/// first word: later opcode words must be checked, sometimes after an address
/// extension. Words are read most-significant byte first. See H8/300 Appendix
/// A and §2, H8/300H §2.4, H8S §2.4 Table 2.2, and H8SX §2.4.
///
/// ```
/// use h8_asm::{isa::insn_len, Mode, Target};
/// assert_eq!(insn_len(&[0x79, 0x00, 0x12, 0x34], Target::H8_300, Mode::Normal), Some(4));
/// assert_eq!(insn_len(&[0x79, 0x00], Target::H8_300, Mode::Normal), None);
/// ```