H' hex constants

DJ Delorie dj@redhat.com
Fri Jul 11 01:23:00 GMT 2008


> > I've been asked to add H'00 syntax for hex constants to gas,
> 
> Is there a specification for this syntax ?

I'll ask, but I suspect it's a simple "replace H' with 0x" thing.

> Hmm - this suggests that changing do_scrub_chars(), although the most 
> straightforward approach, may not be the best way to solve the problem. 

I was also considering a preprocessor just before that.  We want to
look for this:

	<nonalpha>H'[<hexdigit>+]<nonalpha>

which is a lot of state to keep track of for do_scrub_chars().

>   Another solution would be to create a gas specific string to integer 
> conversion function along the lines of strtoul() and use that 
> everywhere.  A much more invasive approach I know, but it may be the 
> only real solution.

Doesn't work - the single quote doesn't survive do_scrub_chars().

> > However, the current code will take something like H'1234 and replace
> > the '1 with 0x30 (48), resulting in a symbol called H49234.
> 
> You lost me there.  Isn't the code supposed to change H'1234 into 0x1234 
> ?  And if you are replacing the two characters '1 with just one byte - 
> 0x30 - shouldn't the resulting string be one byte shorter, ie: H0234 ?

do_scrub_chars() looks for single-quoted characters ("char" type in C)
and converts them to decimal numeric strings.  I.e. 'R' becomes 82, so
foo'R'bar becomes foo82bar.

The parser doesn't seem concerned with missing end quotes, though.
Doing this replacement with so little context checking leads to
interesting error messages.

> Presumably this feature would be enabled on a per-target basis, so that 
> existing ports which do not need to support the syntax would not be 
> affected by the change ?

I've been using '#ifdef H_TICK_HEX' so far.



More information about the Binutils mailing list