[SOLVED] gcc inline asm clobber list question

Programming, for all ages and all languages.
Post Reply
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

[SOLVED] gcc inline asm clobber list question

Post 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
Last edited by dchapiesky on Wed Jan 11, 2017 11:11 am, edited 1 time in total.
Plagiarize. Plagiarize. Let not one line escape thine eyes...
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: gcc inline asm clobber list question

Post by Kevin »

Yes, you should add "memory" to the clobber list then.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: gcc inline asm clobber list question

Post by dchapiesky »

Thanks... I thought so but inline asm isn't my strong suite
Plagiarize. Plagiarize. Let not one line escape thine eyes...
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: [SOLVED] gcc inline asm clobber list question

Post by Octocontrabass »

You should also add "cc" to the clobber list if that function modifies any flags. Everyone seems to forget that one.
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: [SOLVED] gcc inline asm clobber list question

Post by dchapiesky »

'"cc" like carry flag? If you can clarify I need this....
Plagiarize. Plagiarize. Let not one line escape thine eyes...
Icee
Member
Member
Posts: 100
Joined: Wed Jan 08, 2014 8:41 am
Location: Moscow, Russia

Re: [SOLVED] gcc inline asm clobber list question

Post 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.
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: [SOLVED] gcc inline asm clobber list question

Post 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
Last edited by dchapiesky on Fri Jan 13, 2017 7:05 am, edited 1 time in total.
Plagiarize. Plagiarize. Let not one line escape thine eyes...
Icee
Member
Member
Posts: 100
Joined: Wed Jan 08, 2014 8:41 am
Location: Moscow, Russia

Re: [SOLVED] gcc inline asm clobber list question

Post 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.
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: [SOLVED] gcc inline asm clobber list question

Post 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
Plagiarize. Plagiarize. Let not one line escape thine eyes...
Post Reply