سؤال

عند الإشارة إلى الجمعية في دول مجلس التعاون الخليجي، أجد نفسي بانتظام في الاضطرار إلى إضافة كتل ASM فارغة من أجل الحفاظ على المتغيرات على قيد الحياة في كتل السابقة، على سبيل المثال: giveacodicetagpre.

مثال آخر على الغرابة هو أن الكود أدناه يعمل بشكل رائع دون تحسينات، ولكن مع -O3 IT SEG-أخطاء: giveacodicetagpre.

أعتقد أنه يجب القيام به بحقيقة أنه يستخدم الكثير من السجلات.هل هناك شيء أفتقده هنا أو هو تخصيص التسجيل عكس عربات التي تجرها الدواب حقا مع مجموعة دول مجلس التعاون الخليجي؟

هل كانت مفيدة؟

المحلول

What you're missing is that GCC's optimiser will assume that the only side-effect of an asm block is to change the output operands. If those operands are not subsequently used, it may assume that the asm block in unnecessary and can be deleted.

e.g. in your first example, if borrow is not subsequently used, it is free to assume that there is no point in including the asm block at all, because its only side-effect is to update a variable that is never used again. And in the second example, if hi and carry are not used again after the code you've shown, it will probably infer that it can delete pretty much everything!

You can tell GCC that your inline assembly blocks should not be deleted by writing asm volatile(...) instead of just asm(...).

For more detail about this, see http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html (about half-way down the page).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top