【问题标题】:How to generify data for "mov" instruction?如何为“mov”指令生成数据?
【发布时间】:2010-09-30 18:58:52
【问题描述】:

我只需要理解 1 条指令,因此我需要概括这些东西。

我需要在运行时使用以下汇编代码传递结构(用户定义数据类型的对象)。

以下是用户定义的数据类型,即 WESContext:

 typedef struct CWESContext
 {

     BSTR UserName;
     BSTR MachineIP;
     BSTR Certificate;
     BSTR BrowserClienthandle;//Its the handle of the BrowserClient or Java Application   Level Object
     BSTR SessionID;
     BSTR TaskID;// name of the original task

     long LocaleID;//The location of the ultimate Caller
     long FeatureID;//The feature ID mapping to some feature available in WESFW
     long SessionTypeID;//Itmay be; Browser CLient Session, OPC Client Session,              Authenticated OPC Clients session(as they have more rights), WESFWSystemClient.

     SYSTEMTIME TimeStamp;//the time the original task was executed
     DWORD Priority; //task priority of the original task

     struct WESProductCategory
     {
         BSTR ProductCategoryName;
         int serialNo;

         struct WESDimensions
         {
            int weight;        
            struct WESVolume
            {
                int length;
                int heigth;
                int width;
            } oVolume;

            BSTR tempHeight;
            BSTR otherUnknownDimensions;
        } oDimensions;       
    } oWESProductCategory;
} CWESContext;

我已经创建了足够大的 WESContext 块并用示例数据填充它。

      int sizeOfWESContext = sizeof(CWESContext);

      void *pWESContext = malloc(sizeOfWESContext); 
      void *pGenericPtr = pWESContext;
      memset(pWESContext,0,sizeOfWESContext);   

      BSTR *bstrUserName = (BSTR*)pGenericPtr;
      *bstrUserName = SysAllocString(CT2OLE(CA2T(results.at(0).c_str())));
      bstrUserName++;

      pGenericPtr = bstrUserName;

      BSTR *bstrMachineIp = (BSTR*)pGenericPtr;
      *bstrMachineIp = SysAllocString(CT2OLE(CA2T(results.at(1).c_str())));
      bstrMachineIp++;

      pGenericPtr = bstrMachineIp;

      BSTR *bstrCertificate = (BSTR*)pGenericPtr;
     *bstrCertificate = SysAllocString(CT2OLE(CA2T(results.at(2).c_str())));
      bstrCertificate++;

      pGenericPtr = bstrCertificate;

            .....................
            so on so forth...............

如果我通过传递 this 作为对象来调用它:

正常通话: MyCallableMethodUDT(((CWESContext)pWESContext));

现在,我刚刚在调试时从 Visual Studio 的 Dissasembly 视图中提取了以下程序集。

       mov         esi,dword ptr [pWESContext]  
       sub         esp,58h  
       mov         ecx,16h  
       mov         edi,esp  
       rep movs    dword ptr es:[edi],dword ptr [esi]

我只需要了解第三行..

随着我在用户定义结构中增加成员(即这里的 WESContext),它会增加,但我无法断定它是如何增加的......?我需要生成这个指令,以便无论对象是什么,它包含什么大小和任何类型的数据......它应该通过编写上面写的汇编指令调用它来传递。

问候, 乌斯曼

【问题讨论】:

  • 请格式化您的代码!

标签: visual-c++ assembly inline-assembly


【解决方案1】:

ecx 用作第 5 行中rep movs 指令要复制的双字数的计数。它将数据从esi 指向的起始地址复制到以edi 开头的位置.

ecx 中的值将是正在复制的数据的大小。

【讨论】:

  • 实际上是双字数。如果指针是BYTE PTR,或者指令是MOVSB,那么它就是字节数。但是当前的 asm 将与 MOVSD 组装成相同的形式。
  • 啊,是的,我没有注意到指令中存在 DWORD PTR。固定。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-22
  • 1970-01-01
相关资源
最近更新 更多