Far pointers in assembly
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Far pointers in assembly
Some bios interrupts need stored in [es:di] (like get vesa information).
How do I store a pointer like this, es = segment, di = offset?
This doesn't work in nasm. If I remove 'offset' it says that the output file doesn't support segment or something:
mov ax, seg value
mov es, ax
mov di, offset value
Note that the code is part of the 2nd stage bootloader, and it's mixed 16 and 32 bit code.
How is it correctly done? I can't find any good example online.
How do I store a pointer like this, es = segment, di = offset?
This doesn't work in nasm. If I remove 'offset' it says that the output file doesn't support segment or something:
mov ax, seg value
mov es, ax
mov di, offset value
Note that the code is part of the 2nd stage bootloader, and it's mixed 16 and 32 bit code.
How is it correctly done? I can't find any good example online.
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Far pointers in assembly
if you know the seg and offset, you can store it to any other register or memory location, which will thus allow you to pass it around.
Basically a 16-bit far pointer is a 32-bit struct containing two 16 bit unsigned values.
Basically a 16-bit far pointer is a 32-bit struct containing two 16 bit unsigned values.
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Far pointers in assembly
Okay, now the actual address in Segment:Offset looks like this, right?
Address = Segment * 0x10 + Offset;
So this means that:
Segment = (one of the many possibilities) Address / 10h;
Offset = Address % 10h;
Is this correct?
Address = Segment * 0x10 + Offset;
So this means that:
Segment = (one of the many possibilities) Address / 10h;
Offset = Address % 10h;
Is this correct?
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Far pointers in assembly
Okay so I tried to do this:
It freezes when it reaches the div instruction. What could be the problem?
Code: Select all
xor eax, eax
xor ebx, ebx
xor edx, edx
mov dword [TemporaryStorage], vbeControllerInfo
mov ax, word [TemporaryStorage+2]
mov dx, word [TemporaryStorage]
mov bx, 10h
div bx
mov es, ax
mov di, dx
mov ax, 0x4f00
int 10h
cmp ax, 0x004F
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
Re: Far pointers in assembly
quotient overflow?
Re: Far pointers in assembly
You've got the high word and low word around the wrong way, which is probably causing an overflow error (e.g. dx:ax divided by 16 doesn't fit in 16-bits).chibicitiberiu wrote:It freezes when it reaches the div instruction. What could be the problem?
Also, you probably shouldn't be using division in the first place. You could use shifts instead (which is faster and easier), you may be able to get the assembler to calculate it (which is even faster), and the segment register could/should already be correct (which is extremely fast because you don't need to do anything).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re: Far pointers in assembly
You should use bitwise operators for this.
If a trainstation is where trains stop, what is a workstation ?
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Far pointers in assembly
I searched yesterday all the net for bitwise operators in assembly, and found nothing other than AND, OR, XOR...
How do I do bit shifts? Because that was my first idea, just couldn't find the right instructions to do it.
How do I do bit shifts? Because that was my first idea, just couldn't find the right instructions to do it.
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
Re: Far pointers in assembly
shr etc.
If a trainstation is where trains stop, what is a workstation ?
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Far pointers in assembly
shr and shl right? Thanks a lot now it worksgerryg400 wrote:shr etc.
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System