sammielove45 / propgcc

Automatically exported from code.google.com/p/propgcc
1 stars 1 forks source link

Assembler data instructions and enum values #60

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I want to put a constant value that's less than 9 bits into an inline assembly 
sequence but this is impossible with the way inline assembly is expanded.

typedef enum
{
    mode_A,
    mode_B,
} mode;

__asm__ __volatile__
{

"        cmp newmode, %[iMode_B] \n"

"newmode long %[iMode_B] \n"
:
:
         [iMode_B] "i" (mode_B)
:
};

The above will not compile, because %[iMode_B] expands to "#1". This is correct 
when used in the instruction (cmp newmode, #1), but the "long" directive 
doesn't accept the # prefix as valid syntax.

Changing the "i" restriction to something else will not yield the correct 
result: for example, "rC" will generate a directive that would be equivalent to 
"xyz long 1" and the instruction changes to "cmp newmode, xyz". However the 
long directive in the inline assembly will expand to "newmode long xyz" (i.e. 
newmode will be a pointer to xyz) which is not what is intended -- it should be 
"newmode long 1".

This can be solved by modifying the assembler to allow "#" behind the "long" 
directive, or alternatively, expanding the parameter to "1" (not "#1") behind 
the directive. 

Presumably, this also needs to be changed for the "word" and "byte" directives.

(Note, I haven't really thought about how an enum-value of more than 9 bits 
would affect this)

===Jac

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by zhooka...@gmail.com on 7 Feb 2013 at 8:01

GoogleCodeExporter commented 8 years ago
(For some reason the system marked me as the owner of this item)

Original comment by zhooka...@gmail.com on 7 Feb 2013 at 4:38

GoogleCodeExporter commented 8 years ago
Putting "long" directives into inline assembly isn't really a good idea. Use 
COGMEM variables instead.

Original comment by ersm...@hfx.eastlink.ca on 17 May 2013 at 8:46