Assembly language > Assembly discussions

Allocating Memory using VirtualAlloc

(1/1)

Jokaste:

--- Code: ---
                     .Const

                     INCLUDE   Win_AsmLibrary.inc

                     .Code

;   **********************************************************************************
;   *********************** MemoryAlloc **********************************************
;   **********************************************************************************

                     ALIGN   16

PUBLIC   MemoryAlloc

MemoryAlloc :

                     mov      rdx,rcx
                     and      rdx,00000000ffffffffh
                     jnz      @F

                     nop               ; If the only instruction after a label is RET
                     ret               ; Place a NOP or REP RET
@@ :

                     xor      rcx,rcx
                     shl      rdx,12
                     mov      r8,MEM_COMMIT or MEM_RESERVE
                     shr      rdx,12      ; Round to multiple of 4096

                     mov      r9,PAGE_EXECUTE_READWRITE
                     jmp      VirtualAlloc

;   **********************************************************************************
;   *********************** F I N I S H E D ******************************************
;   **********************************************************************************

                     END

--- End code ---

Usualy it is a call VirtualAlloc, not a jump. After this call there would be a RET so it is not necessary to make a CALL. Just correct the stack and JUMP.

Navigation

[0] Message Index

Go to full version