首页 > 代码库 > 汇编-实现基本链表

汇编-实现基本链表

mAlloc proc nSize:dword
    
    add nSize,4
    invoke GlobalAlloc,GMEM_ZEROINIT or GMEM_FIXED,nSize
    
     
    .if eax==0
        invoke MessageBox,NULL,0,NULL,MB_OK
    .endif
    
    ret
mAlloc endp
 
 init_L proc _struct1
LOCAL _headaddress
    invoke mAlloc,sizeof _struct
        mov _headaddress,eax
        assume eax:ptr _struct
        mov [eax].address,eax
      
        assume eax:NOTHING
        mov eax,_headaddress
       ret
init_L endp    
getdata_L proc _L,_i
    
    xor ecx,ecx
    mov eax,_L
    .while ecx<=65536
          assume eax:ptr _struct
          .if ecx==_i
                  mov eax,eax
                  .break
                  ret
        .endif
        
           mov eax,[eax].next
           inc ecx
           
    .endw
    ret

getdata_L endp

insert_L proc   _L,_i
LOCAL _firstaddress
LOCAL _posaddress
     
    mov eax,_L
    mov _firstaddress,eax
    xor ecx,ecx
    .while ecx<_i
        push ecx
        assume eax:ptr _struct
            invoke mAlloc,sizeof _struct
        mov _posaddress,eax
        mov [eax].address,eax
        m2m [eax].back,_firstaddress
        mov eax,_firstaddress
        m2m [eax].next,_posaddress
        m2m _firstaddress,_posaddress     
         
         pop ecx
                
        
        inc ecx
    .endw
     
 
     
    mov eax,_L
    ret
insert_L endp
delete_L proc    _L,_i
 LOCAL _address
        mov eax,_L
        xor ecx,ecx
        .while ecx<65536
            push ecx
            
            assume eax:ptr _struct
            .if ecx==_i
                  
                 m2m _address,[eax].next
                 mov eax,[eax].back
                 m2m [eax].next,_address 
                .break
                ret
            .endif
            mov eax,[eax].next
            
            pop ecx
            inc ecx
        .endw
    ret

delete_L endp