开发者

using 9 function of 21h interrupt 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++?


There are a few prerequisites to this answer:

  1. You are using a compiler that generate 16 bit code since DOS calls only work in 16 bit mode and
  2. Your compiler gets the concept of segments.

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):

  • Small: All segments are the same value and the total of data + code is < 64k
  • Large: All code and data exist in many segments and code + data < 1Meg

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?


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.


#include <dos.h>

FP_SEG(&var);

returns segment of var

FP_OFF(&var);

returns offset of var

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜