Archived

This topic is now archived and is closed to further replies.

Segments and Offsets in C

This topic is 5512 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an interrupt call in C that needs ES set to the segment of a variable and DX set to its offset. How can I get these values? I don''t think I can use pointers, since they point to the whole thing. Sorry if this is a dumb question, I just started C. Any help is appreciated. Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!

Share this post


Link to post
Share on other sites
What exactly are you trying to do?

Chances are you will need a 16 bit compiler - MSVC 1.53 if I remember correctly, or an alternative 16 bit compiler.

You will probably need some inline assembly to call the interrupt. Some knowledge of near and far pointers would be useful.

All in all, these are not topics for a beginner to C!



Share this post


Link to post
Share on other sites
Are you working in DOS? If you are then you''ll need inline assembly code. If you''re working in windows then I''m pretty sure that you shouldn''t be calling interrupts and you shouldn''t be working with functions which want segment registers either.

Share this post


Link to post
Share on other sites

I was writing a mouse driver in C in DOS 6.22. I had already written one in QBasic that could load five different pointers I created and do all sorts of fancy stuff, and I was porting it to C.

right after I posted this I found the functions PF_OFF and PF_SEG in dos.h. They return the segment and offset of a variable. To call the interrupt I was using union REGS and int86x. So now I have it working.

I can''t use inline assembly in C, can I? My compiler doesn''t let me. It recognizes the statement ''asm mov AX,4'' as being inline assembly, but says ''inline assembly not allowed in function...''.

Share this post


Link to post
Share on other sites