当前位置: 首页>>代码示例>>C++>>正文


C++ Assembler::add方法代码示例

本文整理汇总了C++中Assembler::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Assembler::add方法的具体用法?C++ Assembler::add怎么用?C++ Assembler::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Assembler的用法示例。


在下文中一共展示了Assembler::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: translatestore

/**
 * This translates 1 store
* a - the Assembler object
* p - 1 if this is fetch 'b',0 if 'a'
* vmem - VM memory
* xmem - Execution Memory
* vstaddr - DCPU Address of page start in vmem
* vsaddr - DCPU Address of instruction in vmem
* has_other_nw - 1 if the previous fetch used a nextword
*
* returns - 1 if this inst uses a nextword
*/
int translatestore(Assembler &a,char * vmem,char * xmem,uint16_t vstaddr,
		uint16_t vsaddr,int has_other_nw){

	uint16_t inst = *(uint16_t*)(vmem+(2*vsaddr));    //figure out the virtual address of this instruction
	char typ = (inst>>6)&0x1f; //mask and bitshift the argument from the instruction
	printf("Got inst %x and typ %x\n",inst&0xffff,typ&0x3f);
	uint16_t nw;
	nw = *(uint16_t*)(vmem+(2*(vsaddr+2)));
	if(typ<0x18){ //Uses at least a gpreg
		GPReg reg = getreg(typ);
		if(typ<0x08){ //Save gpreg
			a.mov(reg,rbx);
			return 0;
		}else if(typ<0x10){ //Save [gpreg]
			a.mov(ptr(rdi,reg,1),rbx);
			return 0;
		}else{//load [gpreg+nw]
			a.mov(rsi,imm((sysint_t)nw));
			a.add(rsi,reg);
			a.mov(ptr(rdi,rax,1),rsi);
			return 1;
		}
	}if(typ==0x18){ //Is push
		a.mov(ptr(rdi,rdx,1),bx);
		a.dec(dx);
		return 0;
	}if(typ==0x19){ //Is poke
		a.mov(ptr(rdi,rdx,1),bx);
		return 0;
	}if(typ==0x1a){ //Is pock
		a.mov(rsi,imm((sysint_t)nw));
		a.add(rax,rdx);
		a.mov(ptr(rdi,rax,1),bx);
		return 1;
	}if(typ==0x1b){ //SP
		a.mov(dx,bx);
		return 0;
	}if(typ==0x1c){ //PC
		a.shl(rbx,imm(XMEM_TO_VMEM)); //Shift up to xmem offset
		a.jmp(ptr(rbp,rbx));//Jump
	}if(typ==0x1d){ //EX
		a.mov(rcx,rbx);
		return 0;
	}if(typ==0x1e){ //[nw]
		a.mov(esi,imm((sysint_t)nw));
		a.mov(ptr(rdi,esi,1),rbx);
		return 1;
	}
	return 0;
}
开发者ID:baobrien,项目名称:dcpu-trx,代码行数:62,代码来源:translate.cpp

示例2: translatefetch

/**
 * This translates one of the fetches
 *
* a - the Assembler object
* p - 1 if this is fetch 'b',0 if 'a'
* vmem - VM memory
* xmem - Execution Memory
* vstaddr - DCPU Address of page start in vmem
* vsaddr - DCPU Address of instruction in vmem
* has_other_nw - 1 if the previous fetch used a nextword
* 
* returns - 1 if this inst uses a nextword
*/
int translatefetch(Assembler &a,int p,char * vmem,char * xmem,uint16_t vstaddr,
		uint16_t vsaddr,int has_other_nw){

	uint16_t inst = *(uint16_t*)(vmem+(2*vsaddr));    //figure out the virtual address of this instruction
	char typ = p?(inst>>6)&0x1f:0x3f&inst; //mask and bitshift the argument from the instruction
	GPReg tempq = p?rbx:rax;
	GPReg tempw = p?bx:ax;
	printf("Got inst %x and typ %x\n",inst&0xffff,typ&0x3f);
	uint16_t nw;
	if(has_other_nw){
		nw = *(uint16_t*)(vmem+(2*(vsaddr+2)));
	}else{
		nw = *(uint16_t*)(vmem+(2*(vsaddr+1)));
	}
	if(typ<0x18){ //Uses at least a gpreg
		GPReg reg = getreg(typ);
		if(typ<0x08){ //Load gpreg
			a.mov(tempq,reg);
			return 0;
		}else if(typ<0x10){ //Load [gpreg]
			a.mov(tempw,ptr(rdi,reg,1));
			return 0;
		}else{//load [gpreg+nw]
			a.mov(tempq,imm((sysint_t)nw));
			a.add(tempq,reg);
			a.mov(tempw,ptr(rdi,rax,1));
			return 1;
		}
	}if(typ==0x18){ //Is pop
		a.inc(rdx);
		a.mov(tempw,ptr(rdi,rdx,1));
		return 0;
	}if(typ==0x19){ //Is peek
		a.mov(tempw,ptr(rdi,rdx,1));
		return 0;
	}if(typ==0x1a){ //Is pick
		a.mov(tempq,imm((sysint_t)nw));
		a.add(tempq,rdx);
		a.mov(tempw,ptr(rdi,rax,1));
		return 1;
	}if(typ==0x1b){ //SP
		a.mov(tempw,dx);
		return 0;
	}if(typ==0x1c){ //PC
		Label lbl = a.newLabel();
		a.bind(lbl);
		a.lea(tempq,Mem(lbl,1)); //This is somehow the same as 'lea rax,[rip]'
		a.sub(tempq,rbp);		//Subtract the start of xmem from the current ex addr
		a.shr(tempq,imm(XMEM_TO_VMEM)); //Shift the bits down
		return 0;
	}if(typ==0x1d){ //EX
		a.mov(p?rbx:rax,rcx);
		return 0;
	}if(typ==0x1e){ //[nw]
		a.mov(tempq,imm((sysint_t)nw));
		a.mov(tempw,ptr(rdi,rax,1));
		return 1;
	}if(typ==0x1f){ //nextword
		a.mov(tempw,imm((sysint_t)nw));
		return 1;
	}else{ //Is literal
		int16_t v = 0xffff + (int16_t)(typ-0x20);
		a.mov(tempw,imm((sysint_t)v));
		return 0;
	}
	return 0;
}
开发者ID:baobrien,项目名称:dcpu-trx,代码行数:80,代码来源:translate.cpp

示例3: main

int main(int argc, char* argv[])
{
  using namespace AsmJit;

  // ==========================================================================
  // Create assembler.
  Assembler a;

  // Log assembler output.
  FileLogger logger(stderr);
  logger.setLogBinary(true);
  a.setLogger(&logger);

  // We don't want to crash :)
  a.ret();

  // Instructions.
  a.adc(nax,nax);
  a.adc(nax,sysint_ptr(nax));
  a.adc(nax,0);
  a.adc(sysint_ptr(nax),nax);
  a.adc(sysint_ptr(nax),0);
  a.add(nax,nax);
  a.add(nax,sysint_ptr(nax));
  a.add(nax,0);
  a.add(sysint_ptr(nax),nax);
  a.add(sysint_ptr(nax),0);
  a.and_(nax,nax);
  a.and_(nax,sysint_ptr(nax));
  a.and_(nax,0);
  a.and_(sysint_ptr(nax),nax);
  a.and_(sysint_ptr(nax),0);
  a.bswap(nax);
  a.bt(nax,nax);
  a.bt(sysint_ptr(nax),nax);
  a.bt(nax,0);
  a.bt(sysint_ptr(nax),0);
  a.btc(nax,nax);
  a.btc(sysint_ptr(nax),nax);
  a.btc(nax,0);
  a.btc(sysint_ptr(nax),0);
  a.btr(nax,nax);
  a.btr(sysint_ptr(nax),nax);
  a.btr(nax,0);
  a.btr(sysint_ptr(nax),0);
  a.bts(nax,nax);
  a.bts(sysint_ptr(nax),nax);
  a.bts(nax,0);
  a.bts(sysint_ptr(nax),0);
  a.call(nax);
  a.call(sysint_ptr(nax));
  a.cbw();
  a.cwde();
  a.clc();
  a.cld();
  a.cmc();
  a.cmp(nax,nax);
  a.cmp(nax,sysint_ptr(nax));
  a.cmp(nax,0);
  a.cmp(sysint_ptr(nax),nax);
  a.cmp(sysint_ptr(nax),0);
  a.cmpxchg(nax,nax);
  a.cmpxchg(sysint_ptr(nax),nax);
  a.cmpxchg8b(ptr(nax));
  a.cpuid();
  a.dec(nax);
  a.dec(sysint_ptr(nax));
  a.div(nax);
  a.div(sysint_ptr(nax));
  a.idiv(nax);
  a.idiv(sysint_ptr(nax));
  a.imul(nax);
  a.imul(sysint_ptr(nax));
  a.imul(nax,nax);
  a.imul(nax,sysint_ptr(nax));
  a.imul(nax,0);
  a.imul(nax,nax,0);
  a.imul(nax,sysint_ptr(nax),0);
  a.inc(nax);
  a.inc(sysint_ptr(nax));
  a.int3();
  a.lea(nax,sysint_ptr(nax));
  a.mov(nax,nax);
  a.mov(nax,sysint_ptr(nax));
  a.mov(nax,0);
  a.mov(sysint_ptr(nax),nax);
  a.mov(sysint_ptr(nax),0);
  a.movsx(nax,al);
  a.movsx(nax,byte_ptr(nax));
  a.movzx(nax,al);
  a.movzx(nax,byte_ptr(nax));
  a.mul(nax);
  a.mul(sysint_ptr(nax));
  a.neg(nax);
  a.neg(sysint_ptr(nax));
  a.nop();
  a.not_(nax);
  a.not_(sysint_ptr(nax));
  a.or_(nax,nax);
  a.or_(nax,sysint_ptr(nax));
//.........这里部分代码省略.........
开发者ID:Falaina,项目名称:AsmJit-Python,代码行数:101,代码来源:testopcode.cpp

示例4: InjectPureIL

/// <summary>
/// Inject pure IL image.
/// </summary>
/// <param name="netVersion">NET runtime version to use</param>
/// <param name="netAssemblyPath">Path to image</param>
/// <param name="netAssemblyMethod">Method to call</param>
/// <param name="netAssemblyArgs">Arguments passed into method</param>
/// <param name="returnCode">Return code</param>
/// <returns>true on success</returns>
bool ProcessModules::InjectPureIL( const std::wstring& netVersion, 
                                   const std::wstring& netAssemblyPath,
                                   const std::wstring& netAssemblyMethod, 
                                   const std::wstring& netAssemblyArgs, 
                                   DWORD& returnCode )
{
    // split netAssemblyMethod string into class and method names
    size_t idx = netAssemblyMethod.find_last_of( '.' );
    if (idx == std::wstring::npos)
        return false;

    std::wstring MethodName = netAssemblyMethod.substr( idx + 1 );
    std::wstring tmp = netAssemblyMethod;
    tmp.erase( idx );
    std::wstring ClassName = tmp;

    auto address = _memory.Allocate( 0x10000 );

    size_t offset = 4;

    size_t address_VersionString, address_netAssemblyDll, address_netAssemblyClass, 
           address_netAssemblyMethod, address_netAssemblyArgs;

    const std::wstring* strArr[] = { &netVersion, &netAssemblyPath, &ClassName, &MethodName, &netAssemblyArgs };

    size_t* ofstArr[] = { &address_VersionString, &address_netAssemblyDll, &address_netAssemblyClass, 
                          &address_netAssemblyMethod, &address_netAssemblyArgs };

    // Write strings
    for (int i = 0; i < ARRAYSIZE( strArr ); i++)
    {
        size_t len = strArr[i]->length();

        *(ofstArr[i]) = address.ptr<size_t>() + offset;

        // runtime version to use
        if (address.Write( offset, len * sizeof(wchar_t) + 2, strArr[i]->c_str( ) ) != STATUS_SUCCESS)
        {
            returnCode = 5;
            return false;
        }

        offset = DWAlign( offset + len * sizeof(wchar_t) + 2 );
    }

    offset += 4;

    GUID GArray[] = { CLSID_CLRMetaHost, IID_ICLRMetaHost, IID_ICLRRuntimeInfo, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost };

    // COM object GUIDs
    if (address.Write( offset, sizeof(GArray), GArray ) != STATUS_SUCCESS)
    {
        returnCode = 10;
        return false;
    }

    size_t address_CLSID_CLRMetaHost    = address.ptr<size_t>() + offset + 0;
    size_t address_IID_ICLRMetaHost     = address.ptr<size_t>() + offset + 0x10;
    size_t address_IID_ICLRRuntimeInfo  = address.ptr<size_t>() + offset + 0x20;
    size_t address_CLSID_CLRRuntimeHost = address.ptr<size_t>() + offset + 0x30;
    size_t address_IID_ICLRRuntimeHost  = address.ptr<size_t>() + offset + 0x40;

    offset += sizeof(GArray);

    std::wstring libName = L"mscoree.dll";

    NameResolve::Instance().ResolvePath( libName, L"", L"", NameResolve::EnsureFullPath, 0 );

    auto pMscoree = Inject( libName );
    if(!pMscoree)
    {
        returnCode = 15;
        return false;
    }

    // CLRCreateInstance address
    size_t CreateInstanceAddress = (size_t)GetExport( pMscoree, "CLRCreateInstance" ).procAddress;

    // Scary assembler code incoming!
    Assembler a;
    AsmJitHelper ah( a );
    AsmStackAllocator sa( 0x30 );   // 0x30 - 6 arguments of ExecuteInDefaultAppDomain

    // Stack will be reserved manually
    ah.EnableX64CallStack( false );

    Label L_Exit = a.newLabel();
    Label L_Error1 = a.newLabel();
    Label L_Error2 = a.newLabel();
    Label L_Error3 = a.newLabel();
    Label L_Error4 = a.newLabel();
//.........这里部分代码省略.........
开发者ID:CaptainBigSmoke,项目名称:Blackbone,代码行数:101,代码来源:ProcessModules.cpp


注:本文中的Assembler::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。