## Q: how i can print the content of AX register ..plz help.

If you are needing help, or have questions for the different assembly languages available.

Moderator: Moderators

nabil828
Posts: 3
Joined: Thu Sep 04, 2008 10:57 pm

### Q: how i can print the content of AX register ..plz help.

Q: how i can print the content of AX register with INT 0x10 interrupt?

i just wanted to print the amount of Ram.like in tuotorial 2!

***********************************
xor ax, ax
int 0x12
; Now AX = Amount of KB in system recorded by BIOS
***********************************

Andyhhp
Moderator
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1
Contact:
You will have to convert the number to a string to print with an int 0x10 interrupt.

To do this, you need to repeatedly divide the number by the radix that you wish to display it in and store remainders, looping until the number is 0.

Take the number 256 as an example. To convert it to a string in base 10 notation, divide by 10 and store the remainder.

256 / 10 = 25 r 6
25 / 10 = 2 r 5
2 / 10 = 0 r 2

Notice that the remainders form the number starting with the lest significant digit first.

To convert the raw individual digits into ASCII characters, you have to or the values with 0x30 (because 0x30 is '0', 0x31 is '1' etc).

In your specific case, you will want to put aside 6 bytes, 5 for the digits and 1 for the terminating '\$'. Then run the above algorithm and print your resulting string.

On a different note, I remember someone saying that int 0x12/0 was not a reliable method of obtaining the amount of RAM present. The foolproof method is to read it from the CMOS data section and while it is easy in theory, I have yet to find a document that where in CMOS I can find the RAM information and how to decode it.

Andrew

Mike
Posts: 465
Joined: Sat Oct 20, 2007 7:58 pm
Contact:
On a different note, I remember someone saying that int 0x12/0 was not a reliable method of obtaining the amount of RAM present. The foolproof method is to read it from the CMOS data section and while it is easy in theory, I have yet to find a document that where in CMOS I can find the RAM information and how to decode it.
You can get it from the cmos at offsets 0x15 and 0x16 (low and high byte of base address in KB) and 0x17 and 0x18 (same thing but extended memory)...Assuming my document is correct.

I personally tend to use int 0x15 function 0xe801 though to get the memory size as for the reason Andyhhp pointed out.

Andyhhp
Moderator
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1
Contact:
Out of interest, what documentation do you use for CMOS and do you have a link?

Thanks,

Andrew

Mike
Posts: 465
Joined: Sat Oct 20, 2007 7:58 pm
Contact:
Andyhhp wrote:Out of interest, what documentation do you use for CMOS and do you have a link?
Here you go: <a href="http://ivs.cs.uni-magdeburg.de/~zbrog/a ... >Clicky</a>

<a href="http://www.bioscentral.com/misc/cmosmap.htm">Heres another good one</a>

nikoj
Posts: 8
Joined: Sat Oct 04, 2008 11:59 pm
i found this very strange.

how can we get the memory size if the result is stored in AX?

AX is 16 bit register so we can store a number not greater than 65525.
So if we have 512mb ram, that is 524288kb which cannot fit in AX register.

we need to use 32 bit registers for this, but in 32 bit pmode we dont have interrupts....

any explanations?

or can we use 32 bit registers while we are in rmode?

Mike
Posts: 465
Joined: Sat Oct 20, 2007 7:58 pm
Contact:
how can we get the memory size if the result is stored in AX?

AX is 16 bit register so we can store a number not greater than 65525.
So if we have 512mb ram, that is 524288kb which cannot fit in AX register.
You are correct. That interrupt is limited to the first 64K of RAM (Conventional memory).

There are alot of other ways of obtaining memory size. Please see section "Bios: Getting Memory Size" from <a href="http://www.brokenthorn.com/Resources/OS ... ">Tutorial 17</a>

To abtain all memory, you will probably want either BIOS INT 0x15 Function 0xE801 or Function 0xE881. Both of these are described in the above tutorial.
or can we use 32 bit registers while we are in rmode?
You can, it wont work in this situation though as the interrupt uses AX not EAX.

Liza
Posts: 3
Joined: Fri Nov 07, 2008 4:12 pm

### I remember someone

I remember someone saying that int 0x12/0 was not a reliable method of obtaining the amount of RAM present. The foolproof method is to read it from the CMOS data section and while it is easy in theory, I have yet to find a document that where in CMOS I can find the RAM information and how to decode it.

Andyhhp
Moderator
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1
Contact:
iirc, int 12/0 just reads the value from the CMOS data area and returns it in ax. Therefore, reading the CMOS data is no more reliable than int 12/0, and is just extra time and effort to write.

The interrupts dealt with in Tutorial 17 work from the extended BIOS data area which is more reliable.

My suggestion is to follow the tutorial (thats what they are there for) and get the memory information that way.

~Andrew