⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mem.asm

📁 这是一个JPEG解码器,里面使用了MMX,SSE等汇编指令集
💻 ASM
字号:
;// Memory

.686P
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
.MMX
.XMM

INCLUDE jpeg.inc
INCLUDE win32.inc

.CODE

;//=========================================================================
;// Allocate memory
;// params : EAX : requested size
;// return : pointer to memory (null if error), set flags on eax
;//=========================================================================

MEM_Alloc PROC 

        DBG_MEMSIZE

        push        PAGE_READWRITE
        push        MEM_COMMIT
        push        eax
        push        0
        call        VirtualAlloc
        test        eax, eax

        DBG_MEMPTR

        ret        

MEM_Alloc ENDP


;//=========================================================================
;// Free memory
;// params : EAX : pointer
;// return : NULL
;//=========================================================================

MEM_Free PROC 

        test        eax, eax
        jz          Done        
        push        MEM_RELEASE
        push        0
        push        eax
        call        VirtualFree
        ASSERT      (eax == 1)
        sub         eax, eax
Done:
        ret        

MEM_Free ENDP

;//=========================================================================
;// Set memory
;// params : edx : destination
;// params : mm1 : value duplicated 8 times
;// params : ecx : size
;//=========================================================================

MEM_Set PROC 

        PROFILE_IN

        mov         eax, edx
        test        dl, 7
        jnz         NotAligned
Aligned:
        mov         edx, ecx
        and         ecx, NOT(31)
        jz          Less32
        add         eax, ecx
        neg         ecx
Loop32:
        ;// set 32 bytes
        movq        [eax][ecx+8*0], mm1
        movq        [eax][ecx+8*1], mm1
        movq        [eax][ecx+8*2], mm1
        movq        [eax][ecx+8*3], mm1
        add         ecx, 32
        jl          Loop32
Less32:
        ;// last bytes
        and         edx, 31
        jz          Done
        add         eax, edx
        movd        ecx, mm1
        neg         edx
Loop1:
        mov         BPTR [eax][edx], cl
        inc         edx
        jnz         Loop1
Done:
        PROFILE_OUT "Memset"
        ret

        ;// align pointer
NotAligned:
        movd        edx, mm1
        jmp         ATest

ALoop:
        mov         BPTR [eax], dl
        inc         eax
        test        al, 7
        jz          Aligned
ATest:
        dec         ecx
        jge         ALoop
          
        ret

MEM_Set ENDP

END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -