如何为“mov”指令生成数据?

时间:2010-09-30 18:58:53

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

我只需要理解一条单指令,因此我需要对这些指令进行一致化。

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

以下是用户定义的数据类型,即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...............

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

致电Normaly:          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]

我只需要了解第3行......

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

此致 乌斯曼

1 个答案:

答案 0 :(得分:1)

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

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