NASM Forum > Programming with NASM

Why can't I use ORG twice?

(1/2) > >>

ben321:
I'm trying to write a program for DOS that switches to 32-bit protected mode, and have the segment start at physical address 0x00000000. But there's a problem. When in protected mode, the addressing is no longer done based on the 16-byte segment address that real mode uses. Instead it's based on the the start of the much larger segment defined in the GDT. The result of this is that the portion of the code that is written for protected mode needs a separate ORG statement, due to it using a completely different addressing method. But if I have 2 ORG statements in my ASM file, NASM refuses to assemble the code. How do I fix this?

Frank Kotler:
Hi Ben,

You have only one origin in your code: where it starts. I seriously doubt if you want it to be at physical 0! That's where your Interrupt Vector Table lives. Think again about what you really want to do...

Best,
Frank

debs3759:
I'm not sure, as it's a long time since I wrote relevant code, but I think you need to jump to the new CS:IP.

ben321:

--- Quote from: debs3759 on February 12, 2023, 10:17:48 PM ---I'm not sure, as it's a long time since I wrote relevant code, but I think you need to jump to the new CS:IP.

--- End quote ---

Already got that part but the problem is doing the correct far jump. You get that wrong, and bad things happen.

ben321:
The problem comes from this. Even the code that loads from my normal DOS COM file (the address is offset 0x100 and some code segment other than 0). The result is an absolute address for the start of the code that's at (CS*16)+0x100 for the start of the real mode code. However when switching to progressive mode, there's no guaranty that it will be where it should be. It can easily end up NOT where it should be. The result is that as soon as you switch to progressive mode, the addresses represented by the labels in the assembly code are useless. So you can't use the labels anymore, and you need to know the exact physical location of the labels, which requires you doing a bunch of address math, unless there's a way to set the ORG in the assembly code in some way to handle this situation.

Navigation

[0] Message Index

[#] Next page

Go to full version