function 09h interrupts 21h dx = offset of the text , ds = segment of the text
how can i obtain segment and offset in c++?
function 09h interrupts 21h dx = offset of the text , ds = segment of the text
how can i obtain segment and offset in c++?
If you're in real mode, they're the upper and lower 16-bits (respectively) of a FAR pointer to the data.
Environments that use real-mode pointers and let you directly call software interrupts are really rare these days. On any modern OS, you'd be using a user-mode wrapper which generates a sysenter
instruction rather than int
.
There are a few prerequisites to this answer:
In which case it's:
char string [] = "Hello World$";
call_int21h_9 (&string);
where call_int21h_9 is something like:
call_int21h_9 (FAR char *string)
// the FAR above is important and very compiler dependent, it tells the compiler
// that the pointer is a 32bit pointer (16 bit segment and 16 bit offset)
{
mov ah,9
lds dx,string ; this loads the DS:DX segment:offset from the value on the stack
int 21h
}
Further to this, there are several ways to compile a 16 bit application depending on how the segments are set up and used. The two most common are small
and large
(the compiler might call them something else):
There are other layouts of segments (one data, many code; one code and many data, etc) and you'll need to consult the compiler documentation to see what's available.
Of course, your biggest problem is getting a compiler that does 16 bit.
Why not just use cout
or printf
?
#include <dos.h>
FP_SEG(&var);
returns segment of var
FP_OFF(&var);
returns offset of var