www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/08/15:20:28

Message-ID: <370CFD59.82E25337@rendition.com>
From: Jay Yichang Tseng <jtseng AT rendition DOT com>
X-Mailer: Mozilla 4.04 [en] (Win95; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Help needed in getting CR0 under DOS
Lines: 46
Date: Thu, 08 Apr 1999 18:58:11 GMT
NNTP-Posting-Host: 204.242.232.44
NNTP-Posting-Date: Thu, 08 Apr 1999 14:58:11 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

I wrote inline assembly code to access the control register CR0  and
compiled it under djgpp. It ran O.k. in window DOS but gave me general
protection fault under pure DOS environment. The code is as follows.


---------------------------
#include <stdio.h>



unsigned long
getCR0()
{
 unsigned long  result=0;

 __asm__ __volatile__
 ("pushl %%ebx\n
  movl %%cr0, %%ebx\n
  movl %%ebx, %0\n
  popl %%ebx\n"
  : "=b" (result)
  :
  : "%ebx","%cc", "memory"
 );
 return result;
}


void
main()
{
 unsigned long result;

 result=getCR0();
 printf("inside getCR0: result=0x%x\n", result);

}
------------------------

I was able to access registers such as eax and ebx using the same inline
technique under DOS. Anything that I should be aware of?  Thanks.

Jay

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019