In 64-bit NASM, I'm allocating a memory block of 8000 bytes using malloc() from the C library, and when I'm finished with it, I deallocate it by calling free().
My research has come up with a lot of conflicting information about how to do this in 64-bit NASM, and much of the information is 32-bit, where the calling convention is different, or it's C or C++, not NASM.
I think I have the malloc part right, but I'm not sure about the free part. I'm posting this question because I don't want to test it and have a memory block allocated but not freed.
So my two questions are simple:
(1) do I have this right for 64-bit NASM?
(2) is the syntax the same for Windows and Linux?
I'm showing only the malloc and free parts of my program:
extern malloc
extern free
push rdi
; Allocate the memory buffer
mov rdi,8000
call malloc
mov [array_pointer],rax ;array_pointer is initialized in .data
; Code that uses the buffer goes here.
; Free the memory buffer
push rdi
call free
add rsp,8
pop rdi
ret