Author Topic: Getting the segment of a variable in real-mode.  (Read 1702 times)

anphanax

  • Member
  • **
  • Posts: 197
  • Kudos: 11
    • http://june.tripod.com
Getting the segment of a variable in real-mode.
« on: 25 July 2004, 08:23 »
quote:

/* This code sort of works, at least in Borland C++ 4.5, but it's not right, because I need to set the DS register to the value of the segment that string[] resides in, and I have no idea how to do that */

typedef unsigned short WORD;

int main()
{
  char far *string = "Strike any key to exit.$";
  WORD dwsoff = (WORD)&string[0];

  /* Display dollar-sign terminated string. */
  _asm mov ax,0x0900
  _asm mov dx,dwsoff
  _asm int 0x21

  /* Wait for a keypress. */
  _asm mov ax,0x0800
  _asm int 0x21
}



Anyone know how to do this?

EDIT: And for those of you wondering why i'm writing a real-mode MS-DOS application, it's because I can   . I haven't moved to protected mode assembly yet.

ANOTHER EDIT: Does GCC support my usage of intel assembly (where the value you wish to set is the first param, and the value you set it to is the second), or will I have to switch to the AT&T UNIX syntax?

YET ANOTHER EDIT: Is it wise to be doing this to begin with in C? ANSI C is designed so code can be ported, so adding in ASM code could be considered ODD, especially since GCC does a good job optimizing.

[ July 24, 2004: Message edited by: anphanax ]

[ July 24, 2004: Message edited by: anphanax ]


Aloone_Jonez

  • Administrator
  • Member
  • ***
  • Posts: 4,090
  • Kudos: 954
Getting the segment of a variable in real-mode.
« Reply #1 on: 28 July 2004, 03:57 »
I don't know, since I have never written a program that uses both real and protected mode, I have always used either one or the other.

My advice to you if you want to take up assembly programming is to get NASM, it's free and comes in DOS, Win32 and Linux flavours. Start by writing small DOS-16 COM programs (no MZ header) you will be limited to just 64K for your code + data and believe me just 64K is 1000s of lines of code in ASM. Your data is unlikely to be >64K unless it consists of graphics or sound.

You will be amazed at how small assembly is, the binary is now smaller than the source! (unless you linked it with another lib)

Then when you've mastered that you can move on to protected mode. Start of by writing console programs for Win32, DOS32 or Linux. If you want your Win32 programs to run under plain DOS i.e. FreeDOS use WDOSX a combination of DPMI and a powerful console mode Win32 API emulator. It's retardedly simple to use,in goes a console mode Win32 binary and out pops a DOS program complete with built in DPMI and Win32, it also features built in compression so a large program will take up less disk space.

Then if you're realy experianced you can move onto Win32 GUI and Linux X11 GUI applications but don't ask me.

I started programming in BASIC (BBC, QBASIC, VB-DOS WIN-VB), then moved on to assembly, I had a go at C and never liked it, I find asm far easier than C!

I have not programmed for over 4 years now, because I totally lost interest in it when I did an A-level computing, and I am now completely out of practice.
This is not a Windows help forum, however please do feel free to sign up and agree or disagree with our views on Microsoft.

Oh and FUCKMicrosoft! :fu:

hm_murdock

  • VIP
  • Member
  • ***
  • Posts: 2,629
  • Kudos: 378
  • The Lord of Thyme
Getting the segment of a variable in real-mode.
« Reply #2 on: 3 August 2004, 04:29 »
Why would he want to use ASM?

He just said that he doesn't because of portability issues.

ASM sux
Go the fuck ~