Page 1 of 1
[SOLVED] gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:02 am
by dchapiesky
for the code...
Code: Select all
unsigned long b_input(unsigned char *str, unsigned long count)
{
unsigned long len;
asm volatile ("call *0x0000000000100020" : "=c" (len) : "c"(count), "D"(str));
return len;
}
Should "mem" be added in the clobber list? as in:
Code: Select all
unsigned long b_input(unsigned char *str, unsigned long count)
{
unsigned long len;
asm volatile ("call *0x0000000000100020" : "=c" (len) : "c"(count), "D"(str) : "mem");
return len;
}
Since the call to 100020 modifies memory pointed to by str
Just trying to tidy up code and your input will help.
cheers
Re: gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:10 am
by Kevin
Yes, you should add "memory" to the clobber list then.
Re: gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:11 am
by dchapiesky
Thanks... I thought so but inline asm isn't my strong suite
Re: [SOLVED] gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:13 am
by Octocontrabass
You should also add "cc" to the clobber list if that function modifies any flags. Everyone seems to forget that one.
Re: [SOLVED] gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:15 am
by dchapiesky
'"cc" like carry flag? If you can clarify I need this....
Re: [SOLVED] gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:18 am
by Icee
dchapiesky wrote:'"cc" like carry flag? If you can clarify I need this....
CC is for all condition codes, i.e. AF, PF, CF, OF, SF, ZF. Otherwise GCC is free to assume that your inline assembly snippet preserves them and might try to use previous values after the call in generated code.
Re: [SOLVED] gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:21 am
by dchapiesky
Thanks
Final code:
Code: Select all
unsigned long b_input(unsigned char *str, unsigned long count)
{
unsigned long len;
asm volatile ("call *0x0000000000100020" : "=c" (len) : "c"(count), "D"(str) : "cc", "memory");
return len;
}
edited for typo
Re: [SOLVED] gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:23 am
by Icee
dchapiesky wrote:Thanks
Also note that when calling functions from inline assembly many of the usual call convention related aspects may not hold. For instance, the direction flag (DF) may be set and the stack may be misaligned.
Re: [SOLVED] gcc inline asm clobber list question
Posted: Wed Jan 11, 2017 11:27 am
by dchapiesky
Icee wrote:For instance, the direction flag (DF) may be set and the stack may be misaligned.
Yah.. ran into the misaligned stack on a different call from this example.
I am going to open a separate thread for another inline asm question that has been bugging me...
Thank you all for your responses