Skip to content

nasm: Emit a16/a32 for useless address-size prefix#803

Open
mattst88 wants to merge 4 commits into
icedland:masterfrom
mattst88:nasm-a16-a32
Open

nasm: Emit a16/a32 for useless address-size prefix#803
mattst88 wants to merge 4 commits into
icedland:masterfrom
mattst88:nasm-a16-a32

Conversation

@mattst88

@mattst88 mattst88 commented Jun 12, 2026

Copy link
Copy Markdown

Summary

  • In NasmFormatter::format_mnemonic(), emit a16/a32 when instruction.has_address_size_prefix() is true and show_useless_prefixes is enabled

Depends on: #802

Test plan

  • cargo test -p iced-x86 passes
  • NasmFormatter with show_useless_prefixes=true: 67 90 (32-bit) formats as a16 nop

mattst88 added 4 commits June 12, 2026 09:34
Track whether the original encoding contained a 0x67 address-size prefix
that had no semantic effect (i.e. the instruction has no memory
operand). Backed by a free bit (bit 20) in InstrFlags1::flags1,
following the same pattern as has_lock_prefix.
…0x67

OpCodeHandler_Prefix67 flips the address size and delegates to the real
opcode handler. If the decoded instruction has no memory operand of any
kind (OpKind >= MemorySegSI), the 0x67 byte had no semantic effect and
was previously silently discarded. Record it via has_address_size_prefix
so the encoder and formatters can reproduce the original bytes.
Extend write_prefixes() to emit the address-size prefix byte when
instruction.has_address_size_prefix() is true, in addition to the
existing EncoderFlags::P67 path that handles memory operands.
When has_address_size_prefix() is true and show_useless_prefixes is
enabled, emit the NASM address-size keyword (a16 in 32-bit mode, a32
otherwise) so NASM can reproduce the original 0x67-prefixed bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant