www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/21/10:34:26

Message-ID: <8D53104ECD0CD211AF4000A0C9D60AE336F619@probe-2.Acclaim-Euro.net>
From: Shawn Hargreaves <ShawnH AT Probe DOT co DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: Need ASM-Syntax to put code into one asm-instruction
Date: Mon, 21 Dec 1998 15:30:24 -0000
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.0.1460.8)
Reply-To: djgpp AT delorie DOT com

Christian Hofrichter writes:
> Now I have put these instructions into one asm. I have saved the es and
> ds-register temporarly but now I can't change the ds-register without
> getting and general protection fault.

What value are you passing in your progsel parameter? Perhaps this 
isn't a valid selector?

In any case, there is a fundamental flaw in your code, that you are 
letting gcc freely allocate registers for all your input parameters, 
but then are moving them around to other registers of your own choice, 
eg. loading the source and dest pointers into %esi and %edi. You 
can't do that, because what if gcc has already decided to use those 
registers for storing other values?

You can't mix automatic register allocation with using registers for 
specific tasks. If you want to make your own choices, use the fixed 
constraints (a, b, c, d, S, D) to say for sure what registers you 
want to use, or if you want to let gcc do this automatically, give 
it enough control that it can also allocate your temporary 
registers rather than just assuming that something will be free 
for you to use.

It is also worth using the -S switch to have a look at the generated 
code, so you can see exactly how the registers are being allocated.

In any case, I think you are making this unnecessarily difficult 
for yourself. Why not just call movedata()? It does the same thing 
as your code, just as efficiently and more readably, plus it has 
the added benefit that it has already been debugged and is known 
to be working properly :-)


Eli Zaretskii responded:
>>  "movw  %4,%%ds  \n\t" /*<= causes crash */
>
> You are in protected mode now, so you cannot load any arbitrary value 
> into the segment registers.  In protected mode, the only values that can 
> be loaded into these registers are valid selector numbers.  Otherwise you 
> get GPF.

But he wrote %4, not $4. So this would use whatever value was passed 
in from the C progsel variable, apart from the fact that he has 
subsequently clobbered that value by loading other things into the 
same register.


	Shawn Hargreaves.

- Raw text -


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