Page 1 of 1
Segment Register as a Base Register?
Posted: Tue Oct 29, 2013 5:23 am
by Bender
Now please don't kick me out of the OSDev Standard if you see this :
I have always wondered what are base registers, I searched on Google,Wikipedia,Manuals
and many other sources and found out that they are reference points for other addresses,
Now I searched the Wiki for accessing the DOS HMA (High Memory Area),
According to me these are the steps :
1) Enable the A20 Line
2) Set DS to 0xFFFF
3) Use DS as a base with 0xFFFF:0x10
4) Get access to the DOS High Memory Area
What does "use DS as base" mean ?, and the base register I am talking about is SAME as the base register
the Wiki says?
~ANY help/criticism will be appreciated
~Sid123
Re: Segment Register as a Base Register?
Posted: Tue Oct 29, 2013 6:40 am
by qw
The wording is a bit confusing. Segments have base addresses, and in real mode the base address is calculated by multiplying the segment address (the value of a segment register) by sixteen. To that you add an offset, in your case 0x10, to get the physical address that is to be accessed.
A base register on the other hand is a way to specify an offset. For example, in the instruction "mov ax, [bx + si + 2]", BX is the base register, SI is the index register and 2 is the displacement. The result of the calculation is called the effective address, which is the offset into the segment designated by the segment register.
https://en.wikipedia.org/wiki/Intel_8086#Segmentation
Re: Segment Register as a Base Register?
Posted: Tue Oct 29, 2013 8:17 am
by Bender
So what would be the correct procedure of accessing the HMA?
Something like :
mov ax,[ds + x + 0x10]
I know I haven't understood this correctly, Maybe somebody could provide a better way of
representing it?
Re: Segment Register as a Base Register?
Posted: Tue Oct 29, 2013 1:21 pm
by jnc100
The DS register is implied as the segment for all data move instructions provided the memory operand is not relative to SP/ESP/RSP (in which case SS is used) or when it is the destination of a string move (in which case ES is used). Therefore you do not need to specify it explicitly. For example, assuming DS is loaded with 0xffff in real mode, you can access the 16-bit value at 0x100000 with (Intel syntax):
If you want to use a different segment register instead, you need to specify it, e.g.
Regards,
John.
Re: Segment Register as a Base Register?
Posted: Tue Oct 29, 2013 2:28 pm
by qw
sid123 wrote:So what would be the correct procedure of accessing the HMA?
You're already following the correct procedure. Please consult the Intel manuals, this is basic knowledge.