binutils Newspaper
OCTOBER 6, 2026
microblaze — Proposed

microblaze: use md_number_to_chars in md_assemble too

Replaces raw byte assignments with `md_number_to_chars` in MicroBlaze's `md_assemble` for cleaner instruction encoding.

This patch continues the cleanup of MicroBlaze instruction encoding by replacing six instances of direct byte assignments within the md_assemble function with calls to md_number_to_chars. These direct assignments were effectively equivalent to a four-byte store in the target’s byte order. By using md_number_to_chars, the code becomes more concise and consistent with other backends. The associated macros for individual bytes (INST_BYTE0 through INST_BYTE3) are removed as they are no longer used. This change is intended to have no functional impact and has been verified across test suites for both big-endian and little-endian MicroBlaze configurations.

In Details

This patch, the fourth in a series, refactors md_assemble in gas/config/tc-microblaze.c by replacing manual byte-by-byte instruction word assembly with calls to md_number_to_chars. This follows the approach taken in the previous patch for md_apply_fix. The six remaining hardcoded instruction word assembly sites are converted, and the INST_BYTE macros are deleted. The INST_IMM_OFFSET macro is retained as md_number_to_chars doesn't handle immediate field offsets correctly on its own. Testing confirms no functional change across both MicroBlaze endiannesses.

For Context
md_assemble
A function within the MicroBlaze backend that handles the assembly of instructions into machine code.
md_number_to_chars
A generic BFD function that converts a numerical value into a sequence of bytes in the target's endianness, suitable for writing to an object file.
INST_BYTE0
A macro that extracts the most significant byte (or least significant, depending on endianness) of a 32-bit instruction word.
INST_IMM_OFFSET
A macro or constant that specifies the offset within an instruction word where the immediate field is located. This is important for relocations that modify immediate values.
Endianness
The order in which bytes of a multi-byte data word are stored in computer memory. Little-endian stores the least significant byte first, while big-endian stores the most significant byte first.
Filed Under: microblazegasrefactoringinstruction encoding