Pelles C forum

Assembly language => Assembly discussions => Topic started by: Vortex on January 08, 2026, 07:39:06 PM

Title: Getting memory capacity
Post by: Vortex on January 08, 2026, 07:39:06 PM
Here is an example based on the API function GetPhysicallyInstalledSystemMemory :

include     GetMemory.inc

.data

fc1         db 'Compute name = %s'
            db 13,10,0

fc2         db 'The computer %s '
            db 'has %u Gb of memory.',0

nSize       dd 32

.data?

CompName    db 32 dup(?)
Memory      dq ?

.code

start:

    invoke  GetComputerName,\
            ADDR CompName,ADDR nSize

    invoke  printf,ADDR fc1,\
            ADDR CompName

    invoke  GetPhysicallyInstalledSystemMemory,\
            ADDR Memory

    mov     eax,DWORD PTR Memory
    mov     edx,DWORD PTR Memory+4

    mov     ecx,1024*1024
    div     ecx

    invoke  printf,ADDR fc2,ADDR CompName,eax
           
    invoke  ExitProcess,0

END start
Title: Re: Getting memory capacity
Post by: Vortex on January 26, 2026, 06:09:10 PM
Another version based on the API function GlobalMemoryStatusEx :

include     GetMemory.inc

.data

fc1         db 'The computer %s '
            db 'has %u Gb of memory.',0

nSize       dd 32

.data?

CompName    db 32 dup(?)
MemStat     MEMORYSTATUSEX <?>

.code

start:

    invoke  GetComputerName,\
            ADDR CompName,ADDR nSize

    mov     edx,OFFSET MemStat
    mov     MEMORYSTATUSEX.dwLength[edx],SIZEOF(MEMORYSTATUSEX)

    invoke  GlobalMemoryStatusEx,\
            ADDR MemStat

    mov     edx,OFFSET MemStat

    mov     eax,DWORD PTR [edx+MEMORYSTATUSEX.ullTotalPhys]
    mov     edx,DWORD PTR [edx+MEMORYSTATUSEX.ullTotalPhys+4]

    mov     ecx,1024*1024
    div     ecx

    invoke  printf,ADDR fc1,ADDR CompName,eax
           
    invoke  ExitProcess,0

END start