asmjit::BaseMem Class Reference

Base class for all memory operands.

Note
It's tricky to pack all possible cases that define a memory operand into just 16 bytes. The BaseMem splits data into the following parts:

BASE - Base register or label - requires 36 bits total. 4 bits are used to encode the type of the BASE operand (label vs. register type) and the remaining 32 bits define the BASE id, which can be a physical or virtual register index. If BASE type is zero, which is never used as a register-type and label doesn't use it as well then BASE field contains a high DWORD of a possible 64-bit absolute address, which is possible on X64.

INDEX - Index register (or theoretically Label, which doesn't make sense). Encoding is similar to BASE - it also requires 36 bits and splits the encoding to INDEX type (4 bits defining the register type) and id (32-bits).

OFFSET - A relative offset of the address. Basically if BASE is specified the relative displacement adjusts BASE and an optional INDEX. if BASE is not specified then the OFFSET should be considered as ABSOLUTE address (at least on X86). In that case its low 32 bits are stored in DISPLACEMENT field and the remaining high 32 bits are stored in BASE.

OTHER - There is rest 8 bits that can be used for whatever purpose. The x86::Mem operand uses these bits to store segment override prefix and index shift (scale).

Public Types

- Public Types inherited from asmjit::Operand_

Member Functions

Construction & Destruction
Overloaded Operators
Accessors
- Public Member Functions inherited from asmjit::Operand
- Public Member Functions inherited from asmjit::Operand_

Additional Inherited Members

- Public Attributes inherited from asmjit::Operand_
- Static Public Member Functions inherited from asmjit::Operand_

Member Enumeration Documentation

BaseMem::AddrType : uint32_tenum

Address type.

ConstantDescription
kAddrTypeDefault 

Default address type, Assembler will select the best type when necessary.

kAddrTypeAbs 

Absolute address type.

kAddrTypeRel 

Relative address type.

Constructor & Destructor Documentation

BaseMem::BaseMem()constexprconstexprnoexcept[1/3]

Creates a default BaseMem operand, that points to [0].

BaseMem::BaseMem(const BaseMem& other)constexprconstexprnoexcept[2/3]

Creates a BaseMem operand that is a clone of other.

BaseMem::BaseMem(Globals::NoInit_)explicitnoexcept[3/3]

Creates a completely uninitialized BaseMem operand.

Member Function Documentation

void BaseMem::reset()noexcept

Resets the memory operand - after the reset the memory points to [0].

BaseMem BaseMem::clone() constconstexprconstexprnoexcept

Clones the memory operand.

uint32_t BaseMem::addrType() constconstexprconstexprnoexcept

Returns the address type (see AddrType) of the memory operand.

By default, address type of newly created memory operands is always kAddrTypeDefault.

void BaseMem::setAddrType(uint32_t addrType)noexcept

Sets the address type to addrType, see AddrType.

void BaseMem::resetAddrType()noexcept

Resets the address type to kAddrTypeDefault.

bool BaseMem::isAbs() constconstexprconstexprnoexcept

Tests whether the address type is kAddrTypeAbs.

void BaseMem::setAbs()noexcept

Sets the address type to kAddrTypeAbs.

bool BaseMem::isRel() constconstexprconstexprnoexcept

Tests whether the address type is kAddrTypeRel.

void BaseMem::setRel()noexcept

Sets the address type to kAddrTypeRel.

bool BaseMem::isRegHome() constconstexprconstexprnoexcept

Tests whether this memory operand is a register home (only used by Compiler)

void BaseMem::setRegHome()noexcept

Mark this memory operand as register home (only used by Compiler).

void BaseMem::clearRegHome()noexcept

Marks this operand to not be a register home (only used by Compiler).

bool BaseMem::hasBase() constconstexprconstexprnoexcept

Tests whether the memory operand has a BASE register or label specified.

bool BaseMem::hasIndex() constconstexprconstexprnoexcept

Tests whether the memory operand has an INDEX register specified.

bool BaseMem::hasBaseOrIndex() constconstexprconstexprnoexcept

Tests whether the memory operand has BASE or INDEX register.

bool BaseMem::hasBaseAndIndex() constconstexprconstexprnoexcept

Tests whether the memory operand has BASE and INDEX register.

bool BaseMem::hasBaseReg() constconstexprconstexprnoexcept

Tests whether the BASE operand is a register (registers start after kLabelTag).

bool BaseMem::hasBaseLabel() constconstexprconstexprnoexcept

Tests whether the BASE operand is a label.

bool BaseMem::hasIndexReg() constconstexprconstexprnoexcept

Tests whether the INDEX operand is a register (registers start after kLabelTag).

uint32_t BaseMem::baseType() constconstexprconstexprnoexcept

Returns the type of the BASE register (0 if this memory operand doesn't use the BASE register).

Note
If the returned type is one (a value never associated to a register type) the BASE is not register, but it's a label. One equals to kLabelTag. You should always check hasBaseLabel() before using baseId() result.

uint32_t BaseMem::indexType() constconstexprconstexprnoexcept

Returns the type of an INDEX register (0 if this memory operand doesn't use the INDEX register).

uint32_t BaseMem::baseAndIndexTypes() constconstexprconstexprnoexcept

This is used internally for BASE+INDEX validation.

uint32_t BaseMem::baseId() constconstexprconstexprnoexcept

Returns both BASE (4:0 bits) and INDEX (9:5 bits) types combined into a single value.

Remarks
Returns id of the BASE register or label (if the BASE was specified as label).

uint32_t BaseMem::indexId() constconstexprconstexprnoexcept

Returns the id of the INDEX register.

void BaseMem::setBaseId(uint32_t rId)noexcept

Sets the id of the BASE register (without modifying its type).

void BaseMem::setIndexId(uint32_t rId)noexcept

Sets the id of the INDEX register (without modifying its type).

void BaseMem::setBase(const BaseReg& base)noexcept

Sets the base register to type and id of the given base operand.

void BaseMem::setIndex(const BaseReg& index)noexcept

Sets the index register to type and id of the given index operand.

void BaseMem::resetBase()noexcept

Resets the memory operand's BASE register or label.

void BaseMem::resetIndex()noexcept

Resets the memory operand's INDEX register.

void BaseMem::setSize(uint32_t size)noexcept

Sets the memory operand size (in bytes).

bool BaseMem::isOffset64Bit() constconstexprconstexprnoexcept

Tests whether the memory operand has a 64-bit offset or absolute address.

If this is true then hasBase() must always report false.

bool BaseMem::hasOffset() constconstexprconstexprnoexcept

Tests whether the memory operand has a non-zero offset or absolute address.

int64_t BaseMem::offset() constconstexprconstexprnoexcept

Returns either relative offset or absolute address as 64-bit integer.

int32_t BaseMem::offsetLo32() constconstexprconstexprnoexcept

Returns a 32-bit low part of a 64-bit offset or absolute address.

int32_t BaseMem::offsetHi32() constconstexprconstexprnoexcept

Returns a 32-but high part of a 64-bit offset or absolute address.

Note
This function is UNSAFE and returns garbage if isOffset64Bit() returns false. Never use it blindly without checking it first.

void BaseMem::setOffset(int64_t offset)noexcept

Sets a 64-bit offset or an absolute address to offset.

Note
This functions attempts to set both high and low parts of a 64-bit offset, however, if the operand has a BASE register it will store only the low 32 bits of the offset / address as there is no way to store both BASE and 64-bit offset, and there is currently no architecture that has such capability targeted by AsmJit.

void BaseMem::setOffsetLo32(int32_t offset)noexcept

Sets a low 32-bit offset to offset (don't use without knowing how BaseMem works).

void BaseMem::addOffset(int64_t offset)noexcept

Adjusts the offset by offset.

Note
This is a fast function that doesn't use the HI 32-bits of a 64-bit offset. Use it only if you know that there is a BASE register and the offset is only 32 bits anyway. Adjusts the memory operand offset by a offset.

void BaseMem::addOffsetLo32(int32_t offset)noexcept

Adds offset to a low 32-bit offset part (don't use without knowing how BaseMem works).

void BaseMem::resetOffset()noexcept

Resets the memory offset to zero.

void BaseMem::resetOffsetLo32()noexcept

Resets the lo part of the memory offset to zero (don't use without knowing how BaseMem works).