# Class: com.pnfsoftware.jeb.core.units.code.asm.render.GenericCodeFormatter

A base formatter used by the [INativeCodeUnit](INativeCodeUnit). Plugins implementing a processor may override some public and protected methods to customize their disassembly.

## Constructor: GenericCodeFormatter

Description: Create a generic code formatter.

## Constructor: GenericCodeFormatter
- parameter: `mem`, type: `com.pnfsoftware.jeb.core.units.code.asm.memory.IVirtualMemory`

Description: Create a formatter bound to a virtual memory. 

 For testing only.
parameter: mem: virtual memory

## Static Field: MNEMONIC_RIGHT_PADDING_LENGTH_DEFAULT
Type: `int`

Constant value: `10`
Description: Default right padding length for instruction mnemonics.

## Protected Method: addPrefix
- parameter: `insn`, type: `InsnType`
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.asm.processor.IInstructionOperandGeneric`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Add an operand prefix.
parameter: insn: instruction
parameter: opnd: operand
parameter: out: output document part

## Protected Method: addSuffix
- parameter: `insn`, type: `InsnType`
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.asm.processor.IInstructionOperandGeneric`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Add an operand suffix.
parameter: insn: instruction
parameter: opnd: operand
parameter: out: output document part

## Method: createItemIdForAddress
- parameter: `address`, type: `long`
- return type: `long`

Description: Create an item identifier for an address.
parameter: address: address
return: item identifier

## Method: createItemIdForDefaultRegister
- parameter: `regCode`, type: `long`
- return type: `long`

Description: Default method to retrieve item id of a register. By default, Bitsize and bitstart are ignored.
parameter: regCode: Code Register, see [RegisterUtil](RegisterUtil) for details
return: createItemIdForRegister with filtered register based on pure id.

## Method: createItemIdForImmediate
- parameter: `insnAddress`, type: `long`
- parameter: `opndIndexGlobal`, type: `int`
- return type: `long`

Description: Create an item identifier for an immediate.
parameter: insnAddress: instruction address
parameter: opndIndexGlobal: global operand index
return: item identifier

## Method: createItemIdForMnemonic
- parameter: `insn`, type: `InsnType`
- return type: `long`

Description: Create an item identifier for a mnemonic.
parameter: insn: instruction
return: item identifier

## Method: createItemIdForRegister
- parameter: `regCode`, type: `long`
- return type: `long`

Description: Create an item identifier for a register.
parameter: regCode: register code
return: item identifier

## Method: formatAddress
- parameter: `address`, type: `long`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format an address.
parameter: address: address to format
parameter: out: output document part

## Method: formatAddress
- parameter: `address`, type: `long`
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.asm.processor.IInstructionOperandGeneric`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format an address regarding [#getDefaultAddressFormatter()](#getDefaultAddressFormatter())
parameter: address: address to represent
parameter: opnd: optional; IFF address is a relative address
parameter: out: output document part

## Method: formatDataDeclarator
- parameter: `size`, type: `int`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format a data declarator.
parameter: size: data size in bytes
parameter: out: output document part

## Method: formatImm
- parameter: `address`, type: `long`
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.asm.processor.IInstructionOperandSized`
- parameter: `value`, type: `long`
- parameter: `opndIndexGlobal`, type: `int`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format an immediate operand value.
parameter: address: instruction address
parameter: opnd: operand
parameter: value: immediate value
parameter: opndIndexGlobal: global operand index
parameter: out: output document part

## Method: formatInstruction
- parameter: `address`, type: `long`
- parameter: `insn`, type: `InsnType`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Displays only pure assembly code: Mnemonic and Operands, without address and bytecode.
parameter: address: instruction address
parameter: insn: instruction
parameter: out: output document part

## Protected Method: formatMnemonic
- parameter: `address`, type: `long`
- parameter: `insn`, type: `InsnType`
- parameter: `prependPrefix`, type: `boolean`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format an instruction mnemonic.
parameter: address: instruction address
parameter: insn: instruction
parameter: prependPrefix: if true, prepend the instruction prefix
parameter: out: output document part

## Method: formatOperand
- parameter: `address`, type: `long`
- parameter: `insn`, type: `InsnType`
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.IInstructionOperand`
- parameter: `opndIndexGlobal`, type: `int`
- parameter: `opndDepth`, type: `int`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Generic operand formatter. Can be overridden, although not recommended. If the processor uses custom instructions, that is, instructions that are neither [IInstructionOperandGeneric](IInstructionOperandGeneric) or [IInstructionOperandCMA](IInstructionOperandCMA), the processor should override this method.
parameter: address: instruction address
parameter: insn: instruction
parameter: opnd: operand
parameter: opndIndexGlobal: global operand index
parameter: opndDepth: operand nesting depth
parameter: out: output document part

## Protected Method: formatOperands
- parameter: `address`, type: `long`
- parameter: `insn`, type: `InsnType`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format instruction operands.
parameter: address: instruction address
parameter: insn: instruction
parameter: out: output document part

## Protected Method: formatPrefix
- parameter: `address`, type: `long`
- parameter: `insn`, type: `InsnType`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`
- return type: `int`

Description: Format an instruction prefix.
parameter: address: instruction address
parameter: insn: instruction
parameter: out: output document part
return: number of formatted characters

## Protected Method: formatRegister
- parameter: `regValue`, type: `long`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format a register.
parameter: regValue: register value
parameter: out: output document part

## Method: formatRelativeAddress
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.asm.processor.IInstructionOperandGeneric`
- parameter: `address`, type: `long`
- parameter: `out`, type: `com.pnfsoftware.jeb.core.output.code.CodeDocumentPart`

Description: Format a relative address.
parameter: opnd: operand
parameter: address: address to format
parameter: out: output document part

## Method: generateExtraComment
- parameter: `insnAddress`, type: `long`
- parameter: `instruction`, type: `InsnType`
- return type: `java.lang.CharSequence`

Description: Generate an optional string that will be displayed at the line instruction. The default implementation returns null.
parameter: insnAddress: instruction address
parameter: instruction: instruction. Can be null if no instruction is defined at this address.
return: extra comment, or null

## Method: generateExtraMethodComment
- parameter: `address`, type: `long`
- return type: `java.lang.String`

Description: Generate an optional string that will be prepended to a function header comment. The default implementation returns null.
parameter: address: function address
return: extra method comment, or null

## Method: generateExtraSectionHeader
- parameter: `segment`, type: `com.pnfsoftware.jeb.core.units.codeobject.ISegmentInformation`
- return type: `java.lang.String`

Description: Generate an optional extra section header.
parameter: segment: section information
return: extra section header, or null

## Method: generateExtraSegmentHeader
- parameter: `segment`, type: `com.pnfsoftware.jeb.core.units.codeobject.ISegmentInformation`
- return type: `java.lang.String`

Description: Generate an optional extra segment header.
parameter: segment: segment information
return: extra segment header, or null

## Method: generateHeader
- return type: `java.lang.String`

Description: Generate the disassembly header. The default implementation returns the boilerplate line "Code Disassembly".
return: disassembly header

## Protected Method: generateMnemonic
- parameter: `address`, type: `long`
- parameter: `insn`, type: `InsnType`
- return type: `java.lang.String`

Description: Generate an instruction mnemonic.
parameter: address: instruction address
parameter: insn: instruction
return: mnemonic

## Method: getArrayElementPerLine
- return type: `int`

Description: The default implementation returns 10. Can be overridden.
return: a number \>= 1

## Method: getBestClassIdForAddress
- parameter: `address`, type: `long`
- return type: `com.pnfsoftware.jeb.core.output.ItemClassIdentifiers`

Description: Get the best item class identifier for an address.
parameter: address: address
return: item class identifier

## Protected Method: getCachedBooleanProperty
- parameter: `propname`, type: `java.lang.String`
- return type: `boolean`

Description: Convenience method to retrieve and cache \(for 5 second\) a code unit's property.
parameter: propname: code unit's property name
return: the property value \(on failure: false\)

## Protected Method: getCachedIntegerProperty
- parameter: `propname`, type: `java.lang.String`
- return type: `int`

Description: Convenience method to retrieve and cache \(for 5 second\) a code unit's property.
parameter: propname: code unit's property name
return: the property value \(on failure: 0\)

## Protected Method: getCachedStringProperty
- parameter: `propname`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Convenience method to retrieve and cache \(for 5 second\) a code unit's property.
parameter: propname: code unit's property name
return: the property value \(on failure: the empty string\)

## Method: getCodeUnit
- return type: `com.pnfsoftware.jeb.core.units.INativeCodeUnit<InsnType>`

Description: Retrieve the code unit formatted by this object.
return: native code unit

## Protected Method: getCountOfFormattedOperands
- parameter: `insn`, type: `InsnType`
- return type: `int`

Description: Get the number of operands to format.
parameter: insn: instruction
return: operand count

## Method: getDataSeparator
- return type: `java.lang.String`

Description: The default implementation returns the comma string. Can be overridden.
return: data separator

## Method: getDefaultAddressFormatter
- return type: `com.pnfsoftware.jeb.core.units.code.asm.render.AddressFormatter`

Description: Get the default address formatter.
return: default address formatter

## Method: getDefaultNumberFormatter
- return type: `com.pnfsoftware.jeb.core.units.code.asm.render.NumberFormatter`

Description: Get the default number formatter.
return: default number formatter

## Method: getEndianness
- return type: `com.pnfsoftware.jeb.util.io.Endianness`

Description: Retrieve the formatter endianness.
return: endianness

## Method: getInlineCommentString
- return type: `java.lang.String`

Description: The default implementation returns a semi\-column string. Can be overridden.
return: inline comment marker

## Method: getLabelPrefix
- return type: `java.lang.String`

Description: Get the assembly label prefix. Can be overridden.
return: label prefix

## Method: getLabelSuffix
- return type: `java.lang.String`

Description: Can be overridden.
return: label suffix

## Method: getMemory
- return type: `com.pnfsoftware.jeb.core.units.code.asm.memory.IVirtualMemory`

Description: Retrieve the virtual memory being formatted.
return: virtual memory

## Method: getMemoryAccessPrefix
- return type: `java.lang.String`

Description: The default implementation returns the opening square bracket. Can be overridden.
return: memory access prefix

## Method: getMemoryAccessSegmentInfo
- parameter: `insn`, type: `InsnType`
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.IInstructionOperand`
- return type: `java.lang.String`

Description: The default implementation returns the empty string. Can be overridden.
parameter: insn: instruction
parameter: opnd: operand
return: memory access segment text

## Method: getMemoryAccessSizeInfo
- parameter: `insn`, type: `InsnType`
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.asm.processor.IInstructionOperandSized`
- return type: `java.lang.String`

Description: Can be overridden.
parameter: insn: instruction
parameter: opnd: operand
return: memory access size text

## Method: getMemoryAccessSuffix
- return type: `java.lang.String`

Description: The default implementation returns the closing square bracket. Can be overridden.
return: memory access suffix

## Method: getMnemonicRightPaddingLength
- return type: `int`

Description: Get the mnemonic right padding length.
return: padding length

## Method: getMultiLineCommentBegin
- return type: `java.lang.String`

Description: The default implementation returns "slash\-\*". Can be overridden.
return: multiline comment opening marker

## Method: getMultiLineCommentEnd
- return type: `java.lang.String`

Description: The default implementation returns "\*\-slash". Can be overridden.
return: multiline comment closing marker

## Method: getNumberFormatter
- parameter: `item`, type: `com.pnfsoftware.jeb.core.units.code.asm.items.INativeDataItem`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.render.NumberFormatter`

Description: Get a number formatter for a data item.
parameter: item: data item
return: number formatter

## Method: getNumberFormatter
- parameter: `opnd`, type: `com.pnfsoftware.jeb.core.units.code.IInstructionOperand`
- parameter: `createIfNone`, type: `boolean`
- return type: `com.pnfsoftware.jeb.core.units.code.asm.render.NumberFormatter`

Description: Get a number formatter for an operand.
parameter: opnd: operand
parameter: createIfNone: if true, create a formatter if none exists
return: number formatter, or null

## Method: getOperandSeparator
- return type: `java.lang.String`

Description: Can be overridden.
return: operand separator

## Method: getProcedureDefinitionEnd
- return type: `java.lang.String`

Description: Get the procedure definition end marker.
return: procedure end marker

## Method: getProcedureDefinitionStart
- return type: `java.lang.String`

Description: Get the procedure definition start marker.
return: procedure start marker

## Method: getRawDataDeclarator
- parameter: `bitsize`, type: `int`
- return type: `java.lang.String`

Description: The default implementation returns "dX". Can be overridden.
parameter: bitsize: raw data size in bits
return: raw data declarator

## Method: getRegisterName
- parameter: `registerIdentifier`, type: `long`
- return type: `java.lang.String`

Description: The default implementation returns "rX". Should be overridden.
parameter: registerIdentifier: register identifier
return: a register name, never null \(on error, the implementation should return a default         safe string\)

## Method: isDoNotAttemptImmediateToAddressResolution
- return type: `boolean`

Description: Determine whether immediate\-to\-address resolution is disabled.
return: true if immediate\-to\-address resolution is disabled

## Method: setCodeUnit
- parameter: `pbcu`, type: `com.pnfsoftware.jeb.core.units.INativeCodeUnit<InsnType>`

Description: Set the code unit formatted by this object.
parameter: pbcu: native code unit

## Method: setDoNotAttemptImmediateToAddressResolution
- parameter: `doNotResolveImmAsAddr`, type: `boolean`

Description: Set whether immediate\-to\-address resolution is disabled.
parameter: doNotResolveImmAsAddr: true to disable immediate\-to\-address resolution

## Method: setMnemonicRightPaddingLength
- parameter: `length`, type: `int`

Description: Set the mnemonic right padding length.
parameter: length: padding length

