www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/03/14/03:04:31

Date: Thu, 14 Mar 96 07:37:03 GMT
From: sgs1 AT scigen DOT co DOT uk (Gavin Smyth)
Message-Id: <9603140737.AA02146@ scigen.co.uk>
To: djgpp AT delorie DOT com
Subject: Problem with register assignments in embedded assembler

I have a couple of embedded assembler questions to ask a DJGPP expert
with respect to assigning registers within C.

First, I want to assign a value to a register (or at least I think I
do!). I use the "offset" variable below in a bit of embedded assembler
and reckoned that it'd help the compiler a bit if I explicitly assigned
it to a register at the definition instead of waiting for the assembler
inputs section. The value is not altered during the loop, so a const
also seemed in order, thus I defined it with:

  register const Coord offset asm( "%ebx" ) = full_width - width;

However, the compiler (DJGPP V2.0) objected with:

  Error: rest of line ignored. First character is `%'

where the offending line in the intermediate (assembly) file reads:

  .def	_%ebx;	.val	3;	.scl	4;	.type	016;	.endef

Removing the const works, and the "_%ebx" is replaced with "_offset" -
the moral of this is not to make a register variable const, but should
making it const be a no-no? Or am I misinterpreting the asm clause here?

The second question deals with another bit of the same code: it's a
routine to copy stuff between "DOS space" and data space, but using REP
MOVS to speed things along. Now the destination of a movs can only be
the ES segment (can't it? the segment override prefix refers to the
source of a MOVS doesn't it?) so I need to nobble ES with the DOS
selector in this bit of code. I wanted to just list "%es" in the changed
by asm section of the embedded block, as in:

  asm volatile( ... my code
                : /* No outputs */
                : "a" (_width), "b" (offset), etc...
                :  "%eax", ..., "%es", "cc" );

and let the compiler preserve it automatically. However, it was not to
be - I get:

  unknown register name `%es' in `asm'

The workaround is just pushing ES at the start of the code block and
popping it at the end, but shouldn't the compiler know about ES?

Do either of these represent buglets in the compiler? In GCC or in DJGPP?
Or am I simply being denser than usual?

Gavin

- Raw text -


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