Programming, for all ages and all languages.
dchapiesky
Member
Posts: 204 Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky
Post
by dchapiesky » Wed Jan 11, 2017 11:02 am
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
Posts: 1071 Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:
Post
by Kevin » Wed Jan 11, 2017 11:10 am
Yes, you should add "memory" to the clobber list then.
dchapiesky
Member
Posts: 204 Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky
Post
by dchapiesky » Wed Jan 11, 2017 11:11 am
Thanks... I thought so but inline asm isn't my strong suite
Plagiarize. Plagiarize. Let not one line escape thine eyes.. .
Octocontrabass
Member
Posts: 5513 Joined: Mon Mar 25, 2013 7:01 pm
Post
by Octocontrabass » Wed Jan 11, 2017 11:13 am
You should also add "cc" to the clobber list if that function modifies any flags. Everyone seems to forget that one.
dchapiesky
Member
Posts: 204 Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky
Post
by dchapiesky » Wed Jan 11, 2017 11:15 am
'"cc" like carry flag? If you can clarify I need this....
Plagiarize. Plagiarize. Let not one line escape thine eyes.. .
Icee
Member
Posts: 100 Joined: Wed Jan 08, 2014 8:41 am
Location: Moscow, Russia
Post
by Icee » Wed Jan 11, 2017 11:18 am
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.
dchapiesky
Member
Posts: 204 Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky
Post
by dchapiesky » Wed Jan 11, 2017 11:21 am
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
Posts: 100 Joined: Wed Jan 08, 2014 8:41 am
Location: Moscow, Russia
Post
by Icee » Wed Jan 11, 2017 11:23 am
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.
dchapiesky
Member
Posts: 204 Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky
Post
by dchapiesky » Wed Jan 11, 2017 11:27 am
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.. .