Reizeru
Reizeru

Reputation: 11

How to get memory size?

I use the instruction 0x15, ax = 0xe801 to get the total memory in the kernel loader and move it to later read from the memory cell in the kernel. but the result is not like what you need. Bootsect code

xor cx,cx
xor dx,dx
mov ax,0xe801
int 0x15
mov ax,cx
mov bx,dx
mov [0x00000600],ax
mov [0x00000620],bx

Result - 00@4

Upvotes: 1

Views: 363

Answers (1)

Brendan
Brendan

Reputation: 37222

How to get memory size?

Which "memory size"?

If you want to get the total amount of RAM installed then you probably need to use "System Management BIOS" tables; but this is number (which includes things like "RAM stolen by firmware" and "RAM stolen by integrated graphics") has very little practical use.

If you want a list of areas of RAM that the OS can use; then this is literally a list and not a single number. To get the list you'd use "int 0x15, eax=0xE820", and once you have the list (and hopefully sanitized it) you could add up the sizes of "usable RAM" areas (and ignore areas reported as "reserved", "ACPI non-volatile", ... ) to get the total amount of RAM an OS can use.

Note: For ancient computers there were many other functions ("int 0x12", "int 0x15, ax=0xE881", "int 0x15, ax=0xE801", "int 0x15, ah=0xC7", "int 0x15, ah=0x8A", "int 0x15, ax=0xDA88", "int 0x15, ah=0x88") plus a few other methods (CMOS locations, probing); where different computers supported some (and never all) of the options. Fortunately all of this was deprecated in the early 1990s and there's no point caring about any of it now (because computers that are 25+ years old mostly stopped being used 15 years ago).

Upvotes: 2

Related Questions