---
name: "x86_format_insn"
section: "3"
platform: "linux"
package: "libdisasm-dev"
version: "0.23-7"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/x86_format_insn"
---

# x86\_format\_insn(3)

generate a string representation of a disassembled instruction.

## NAME

x86\_format\_insn, x86\_format\_mnemonic, x86\_format\_operand, x86\_format\_header - generate a string representation of a disassembled instruction.

## SYNOPSIS

**#include \<libdis.h\>**\

**int x86\_format\_operand(x86\_op\_t \***op**, char \***buf**, int** len**,** \
\
 	**enum x86\_asm\_format** format**);**

**int x86\_format\_mnemonic(x86\_insn\_t \***insn**, char \***buf**, int** len**,**\
\
 	**enum x86\_asm\_format** format **);**

**int x86\_format\_insn(x86\_insn\_t \***insn**, char \***buf**, int** len**,** \
\
 	**enum x86\_asm\_format** format **);**

**int x86\_format\_header( char \***buf**, int** len**,** \
\
 	**enum x86\_asm\_format** format**);**\

## DESCRIPTION

**x86\_format\_insn** generates an assembly-langauge representation of the disassembled instruction in the specified format. **x86\_format\_mnemonic** and  are called by **x86\_format\_operand** to format the instruction mnemonic and operands, respectively, but they may be invoked directly by the user. Each of these routines fills buffer **buf** of **len** bytes with an ASCII string representing the instruction, mnemonic, or operand.\
 **x86\_format\_header** fills buffer **buf** of **len** bytes with a description of the specified format.

The following formats are available:

	**native\_syntax** : Intel syntax with address and hex \
\
 	**intel\_syntax** : Intel x86 syntax\
\
 	**att\_syntax** : AT&T Syntax\
\
 	**raw\_syntax** : Pipe-delimited internal format\
\
 	**xml\_syntax** : XML representation

**Native** syntax uses dest, src ordering and displays\
 the address, opcode bytes, and instruction in tab-delimited\
 format:\
\
        **"ADDRESS\\tBYTES\\tMNEMONIC\\tDEST\\tSRC\\tIMM"**

**Intel** syntax uses dest, src ordering and displays the instruction in tab-and-comma delimited format:\
\
        **"MNEMONIC\\tDEST, SRC, IMM"**

**AT&T** syntax uses src, destordering and displays the instruction in tab-and-comma delimited format:\
\
        **"MNEMONIC\\tSRC, DEST, IMM"**

**Raw** syntax displays all details of the instruction in pipe-delimited format:\
\
        **"ADDRESS\|OFFSET\|SIZE\|BYTES\|PREFIX\|PREFIX\_STRING\|**

**XML** syntax displays all details of the instruction in XML format:\
\
         GROUP\|TYPE\|NOTES\|MNEMONIC\|CPU\|ISA\|FLAGS\_SET\|\
\
         FLAGS\_TESTED\|STACK\_MOD\|STACK\_MOD\_VAL"\
\
         \[\|OP\_TYPE\|OP\_DATATYPE\|OP\_ACCESS\|OP\_FLAGS\|OP\]\*"\
\
         **"\<x86\_insn\>**\
\
                **\<address rva= offset= size= bytes=/\>**\
\
                **\<prefix type= string=/\>**\
\
                **\<mnemonic group= type= string= cpu= isa= note= /\>**\
\
                **\<flags type=set\>**\
\
                   **\<flag name=\>**\
\
                **\</flags\>**\
\
                **\<stack\_mod val= \>**\
\
                **\<flags type=tested\>**\
\
                   **\<flag name=\>**\
\
                **\</flags\>**\
\
                **\<operand name=\>**\
\
                   **\<register name= type= size=/\>**\
\
                   **\<immediate type= value=/\>**\
\
                   **\<relative\_offset value=/\>**\
\
                   **\<absolute\_address value=\>**\
\
                      **\<segment value=/\>**\
\
                   **\</absolute\_address\>**\
\
                   **\<address\_expression\>**\
\
                      **\<segment value=/\>**\
\
                      **\<base\>**\
\
                         **\<register name= type= size=/\>**\
\
                      **\</base\>**\
\
                      **\<index\>**\
\
                         **\<register name= type= size=/\>**\
\
                      **\</index\>**\
\
                      **\<scale\>**\
\
                         **\<immediate value=/\>**\
\
                      **\</scale\>**\
\
                      **\<displacement\>**\
\
                         **\<immediate value=/\>**\
\
                         **\<address value=/\>**\
\
                      **\</displacement\>**\
\
                   **\</address\_expression\>**\
\
                   **\<segment\_offset\>**\
\
                      **\<address value=/\>**\
\
                   **\</segment\_offset\>**\
\
                **\</operand\>**\
\
             **\</x86\_insn\>"** \

## EXAMPLES

The following will print **insn** in Intel syntax:

void att\_print( x86\_insn\_t \*insn ) {\
\
         char line\[256\];\
\
         x86\_format\_insn(insn, line, 256, intel\_syntax);\
\
         printf( "%s\\n", line);\
 }

The following routine formats an instruction manually using AT&T syntax:

void manual\_print( x86\_insn\_t \*insn, void \*arg ) {\
\
         char buf\[128\];\
\
         int i;\
\
         printf("%08lX", insn-\>addr );\
\
         for ( i = 0; i \< 10; i++ ) {\
\
                 if ( i \< insn-\>size ) {\
\
                         printf(" %02X", insn-\>bytes\[i\]);\
\
                 } else {\
\
                         printf("   ");\
\
                 }\
\
         }\
\
         x86\_format\_mnemonic( insn, buf, 128, att\_syntax );\
\
         printf( "\\t%s\\t", buf );\
\
         if ( insn-\>operands\[op\_src\].type != op\_unused ) {\
\
                 x86\_format\_operand( &insn-\>operands\[op\_src\],\
\
                                insn, buf, 128, att\_syntax );\
\
                 /\* if src is present, so is dest \*/\
\
                 printf("%s, ", buf);\
\
         }\
\
         if ( insn-\>operands\[op\_dest\].type != op\_unused ) {\
\
                 x86\_format\_operand( &insn-\>operands\[op\_dest\],\
\
                                insn, buf, 128, att\_syntax );\
\
                 printf("%s", buf);\
\
         }\
\
         if ( insn-\>operands\[op\_imm\].type != op\_unused ) {\
\
                 x86\_format\_operand( &insn-\>operands\[op\_imm\],\
\
                                insn, buf, 128, att\_syntax );\
\
                 /\* if src is present, so is dest \*/\
\
                 printf(", %s", buf);\
\
         }\
\
         printf("\\n");\
 }\

## SEE ALSO

[libdisasm(7)](/libdisasm/7.md), [x86\_disasm(3)](/x86_disasm/3.md), [x86\_init(3)](/x86_init/3.md), [x86dis(1)](/x86dis/1.md)
