News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Array

Started by six_L, July 03, 2006, 02:02:08 PM

Previous topic - Next topic

six_L

Hey,all
I want to translate the code into asm.
;//====================================================
for ( UINT i = 0; i < nMaxPipe; i++ )
{
   PipeInst.hPipe = CreateNamedPipe ( lpPipeName,PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED, \
            PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_WAIT, nMaxPipe, 0, 0, INFINITE, NULL ) ;
   if ( PipeInst.hPipe == INVALID_HANDLE_VALUE )
   {
      DWORD dwErrorCode = GetLastError () ;
      return ;
   }
      
   HANDLE hRet = CreateIoCompletionPort ( PipeInst.hPipe, hCompletionPort, i, nMaxThread ) ;
   if ( hRet == NULL )
   {
      CloseHandle ( hCompletionPort ) ;
      return ;
   }
      
   PipeInst.ov.hEvent = CreateEvent ( NULL, false, false, false ) ;
   ConnectNamedPipe ( PipeInst.hPipe, &(PipeInst.ov) ) ;
}
;//====================================================

nMaxPipe input from user.
i don't know how define the "PipeInst.hPipe" and "PipeInst.ov.hEvent" array.
please help.

regards

Ratch

#1
six_L,

     What can I say?  Here it is.  I had to make a lot of assumtions concerning the variables and array definition because that info was missing.  The loop goes from high to low, but that should not matter.  Ask if you have any questions. Ratch

Damn, I hate it when the "code" function of this board trims off one space at the beginning of each line.



D EQU DWORD PTR

ov STRUC
  hEvent DWORD ?
ov ENDS

PipeInst STRUC
hPipe DWORD ?
ov$        = $
ov          {}
PipeInst ENDS

.DATA?
nMaxPipe        DWORD ?
dwErrorCode     DWORD ?
hRet            DWORD ?
hCompletionPort DWORD ?
nMaxThread      DWORD ?
i               DWORD ?

    .CODE
START:
XOR EBP,EBP                       ;EBP=0
MOV ECX,[nMaxPipe]
MOV EAX,PipeInst                  ;EAX=size of one array element in bytes
DEC ECX
MUL [nMaxPipe]                    ;EAX=number of bytes needed for full array
MOV [i],ECX                       ;i=nMaxPipe-1
PUSH EAX                          ;EAX=number of bytes needed for full array
INVOKE GlobalAlloc,GMEM_FIXED OR GMEM_ZEROINIT,EAX ;alloc bytes for array
POP ECX                           ;ECX=number of bytes needed for full array
PUSH EAX                          ;***push hmem for GlobalFree below
PUSH ECX                          ;ECX=number of bytes needed for full array
ADD [ESP],EAX                     ;[ESP]=address at end of full array
SUB D[ESP],PipeInst               ;[ESP]=address of last element of array

.REPEAT
   MOV EAX,D[ESP]                  ;EAX=address of current array element
   .IF  [EAX.PipeInst.hPipe] == INVALID_HANDLE_VALUE
     INVOKE GetLastError
     MOV [dwErrorCode],EAX
     .BREAK .IF TRUE
     RET
   .ENDIF

   MOV EAX,D[ESP]                  ;EAX=address of current array element
   INVOKE CreateIoCompletionPort,[EAX.PipeInst.hPipe],[hCompletionPort],[i],[nMaxThread]
   MOV [hRet],EAX

   .IF EAX == EBP                  ;EAX=hRed
     INVOKE CloseHandle,[hCompletionPort]
     .BREAK .IF TRUE
   .ENDIF

   INVOKE CreateEvent,EBP,EBP,EBP,EBP ;EBP=FALSE=NULL=0
   MOV ECX,D[ESP]                  ;EAX=address of current array element
   LEA EDX,[ECX+ov$]
   MOV [ECX.PipeInst.hEvent],EAX
   INVOKE ConnectNamedPipe,[ECX.PipeInst.hPipe],EDX

  SUB D[ESP],PipeInst             ;back up one array element
  DEC [i]
.UNTIL SIGN?
POP ECX                          ;balance stack

CALL GlobalFree                  ;***hmen handle already pushed above

RET

END START

James Ladd

Ratch,

Thanks for taking the time to respond in detail to six_L's request.

six_L

Hello,Ratch
thanks you for the detailed and valuable answer.
:U

hello,James Ladd
i'm messy why you did "Thanks". do you think i'm late to say "Thanks" ?
regards