Output°ú inputÀº "constraint" (variable)µéÀÇ ½°Ç¥·Î ±¸ºÐµÈ ¸®½ºÆ®·Î ±¸¼ºµË´Ï´Ù.
Constraint´Â ¾Æ·¡ÀÇ ¹®ÀÚµé°ú ¸î°¡Áö modifierµéÀÇ Á¶ÇÕÀ¸·Î Çã¿ëµÇ´Â operandÀÇ Á¾·ù¿Í ±× operand°¡ inline assembly¿¡¼ ¾î¶»°Ô »ç¿ëµÇ´ÂÁö¸¦ ³ªÅ¸³À´Ï´Ù. ¾Æ·¡ÀÇ ¸®½ºÆ®´Â ¿ÏÀüÇÏÁö ¾Ê½À´Ï´Ù. Gcc ¸Þ´º¾óÀ» ÂüÁ¶Çϼ¼¿ä.
Architecture°¡ ÀϹÝÀûÀ¸·Î Áö¿øÇÏ´Â ¸ðµç addressing modeÁß Çϳª¸¦ »ç¿ëÇÏ´Â memory operand.
¹ü¿ë ·¹Áö½ºÅÍ operand.
·¹Áö½ºÅ͸¦ ÀûÁ¢ ÁöÁ¤ÇÏ´Â constraint. Architecture¸¶´Ù ´Ù¸¥ ¹®ÀÚµéÀ» Á¤ÀÇÇÕ´Ï´Ù. 'd', 'a', 'f'´Â 68000/68020¿¡¼ ¾²´Â ¹®ÀÚµéÀÔ´Ï´Ù.
Á¤¼ö immediate operand. AssembleÇÒ ¶§°¡ µÇ¾î¾ß ¾Ë ¼ö ÀÖ´Â symbol°ª(ÁÖ¼Ò)µéµµ ÇØ´çµË´Ï´Ù.
°ªÀ» Á¤È®È÷ ¾Ë°í ÀÖ´Â Á¤¼ö. Symbol°ªµéÀº ÇØ´çµÇÁö ¾Ê½À´Ï´Ù.
¹Ì¸® Á¤ÇØÁø ¹üÀ§¾ÈÀÇ Á¤¼ö immediate operand. ¿¹¸¦ µé¾î 68000¿¡¼ 'I'´Â 1¿¡¼ 8»çÀÌÀÇ immediate operand¸¦ ¶æÇϸç shift operationÀÇ shift cound·Î ¾²ÀÔ´Ï´Ù.
Compling machine°ú target machineÀÇ floating Ç¥Çö ¹æ½ÄÀÌ °°À» ¶§ immediate floating operand¸¦ Çã¿ëÇÕ´Ï´Ù.
Immediate floating operand.
Machine¿¡ µû¶ó Á¤ÀǵǴ ƯÁ¤ÇÑ ¹üÀ§³»ÀÇ immediate floating point operand.
¹ü¿ë ·¹Áö½ºÅÍ, memory, immediate operand Áß ¹«¾ùÀÌ¶óµµ µË´Ï´Ù.
¾î¶°ÇÑ operand¶óµµ Çã¿ëÇÕ´Ï´Ù.
À¯È¿ÇÑ ÁÖ¼Ò°¡ Çã¿ëµË´Ï´Ù. Load address, push addressµîÀÇ instruction¿¡ ¾²ÀÔ´Ï´Ù.
Machine-dependent.
a, b, c, or d register
a, or d register (for 64-bit ints)
Floating point register
First (top of stack) floating point register
Second floating point register
a register
b register
c register
d register
di register
si register
Constant in range 0 to 31 (for 32bit shifts)
Constant in range 0 to 63 (for 64bit shifts)
0xff
0xffff
0, 1, 2, or 3 (shifts for lea instruction)
Constant in range 0 to 255 (for out instruction)
Standard 80387 floating point constant
Constraint modifierµéÀº ±× º¯¼ö°¡ ¾î¶»°Ô »ç¿ëµÇ´Â Áö¸¦ compiler¿¡°Ô ¾Ë·ÁÁÝ´Ï´Ù. ¾Æ·¡ÀÇ ¸®½ºÆ®´Â ¿ÏÀüÇÏÁö ¾Ê½À´Ï´Ù. Gcc ¸Þ´º¾óÀ» ÂüÁ¶Çϼ¼¿ä.
º¯¼öÀÇ °ªÀÌ ¹Ù²ñÀ» ³ªÅ¸³À´Ï´Ù. Outputµé¿¡ ´ëÇØ¼´Â ÀÌ modifier°¡ ¹Ýµå½Ã ÁöÁ¤µÇ¾î ÀÖ¾î¾ß ÇÕ´Ï´Ù.
Early clobber. ´ÙÀ½ Àý¿¡¼ ÀÚ¼¼È÷ ¼³¸íÇϰڽÀ´Ï´Ù.
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int a, sum; a = atoi(argv[1]); __asm__ __volatile__( "movl %1, %0 \n\t" "addl %2, %0 \n\t" "addl %3, %0 \n\t" "addl %4, %0 \n\t" "addl %5, %0 " : "=g" (sum) : "g" (a), "g" (a+1), "g" (a+2), "g" (a+3), "g" (a+4)); printf("a=%d, sum=%d\n", a, sum); return 0; } |
À§ÀÇ ÇÁ·Î±×·¥À» ÄÄÆÄÀÏÇϸé
.file "early_clobber.c" .version "01.01" gcc2_compiled.: .section .rodata .LC0: .string "a=%d, sum=%d\n" .text .align 4 .globl main .type main,@function main: pushl %esi pushl %ebx movl 16(%esp),%eax pushl $0 pushl $10 pushl $0 pushl 4(%eax) call __strtol_internal movl %eax,%esi addl $16,%esp leal 1(%esi),%edx leal 2(%esi),%ebx leal 3(%esi),%ecx leal 4(%esi),%eax #APP movl %esi, %edx addl %edx, %edx addl %ebx, %edx addl %ecx, %edx addl %eax, %edx #NO_APP pushl %edx pushl %esi pushl $.LC0 call printf xorl %eax,%eax addl $12,%esp popl %ebx popl %esi ret .Lfe1: .size main,.Lfe1-main .ident "GCC: (GNU) 2.95.4 20010902 (Debian prerelease)" |
#APP¿Í #NOAPP »çÀÌÀÇ inline assembly¿¡¼ %0 (sum)¿¡ %edx°¡ ÇÒ´çµÇ¾úÀ½À» ¾Ë ¼ö ÀÖ½À´Ï´Ù. ±×·±µ¥ #APP¾Æ·¡ µÎ¹øÂ°ÁÙÀÌ addl %edx, %edx·Î %2 (a+1)µµ %edx·Î ÇÒ´çµÇ¾ú½À´Ï´Ù. Gcc´Â Ç×»ó ¸ðµç input º¯¼öµéÀÌ ´Ù »ç¿ëµÈ ÈÄ¿¡ output º¯¼öµéÀÌ ¾²ÀÎ´Ù°í °¡Á¤Çؼ input º¯¼ö¿Í output º¯¼ö¸¦ °°Àº operand¿¡ ÇÒ´çÇϱ⵵ ÇÕ´Ï´Ù. Input, outputÀÌ ÇϳªÀÇ operand¿¡ ÇÒ´çµÇ°í À§ÀÇ ¿¹Ã³·³ inputº¸´Ù outputÀ¸·Î ¸ÕÀú¾²ÀÌ°Ô µÇ¸é Ʋ¸° °á°ú°¡ ³ª¿É´Ï´Ù.
ÀÌ·± °æ¿ì¿¡´Â gcc¿¡°Ô ±× output º¯¼ö´Â inputÀÇ °ªµéÀÌ ¸ðµÎ »ç¿ëµÇ±â Àü¿¡ °ªÀÌ ¹Ù²ð ¼ö ÀÖ´Ù´Â °ÍÀ» ¾Ë·ÁÁÖ¾î¾ß ÇÕ´Ï´Ù. À̰ÍÀ» ¾Ë·ÁÁÖ±â À§ÇÑ modifier°¡ early clobber modifier '&' ÀÔ´Ï´Ù. À§ÀÇ ÇÁ·Î±×·¥¿¡¼ output constraint "=g" (sum)À» "=&g" (sum)À¸·Î ¹Ù²Ù°í ´Ù½Ã ÄÄÆÄÀÏÇÏ¸é ´ÙÀ½°ú °°Àº °á°ú°¡ ³ª¿É´Ï´Ù.
.file "early_clobber.c" .version "01.01" gcc2_compiled.: .section .rodata .LC0: .string "a=%d, sum=%d\n" .text .align 4 .globl main .type main,@function main: pushl %edi pushl %esi pushl %ebx movl 20(%esp),%eax pushl $0 pushl $10 pushl $0 pushl 4(%eax) call __strtol_internal movl %eax,%esi addl $16,%esp leal 1(%esi),%ebx leal 2(%esi),%ecx leal 3(%esi),%edx leal 4(%esi),%eax #APP movl %esi, %edi addl %ebx, %edi addl %ecx, %edi addl %edx, %edi addl %eax, %edi #NO_APP movl %edi,%eax pushl %eax pushl %esi pushl $.LC0 call printf xorl %eax,%eax addl $12,%esp popl %ebx popl %esi popl %edi ret .Lfe1: .size main,.Lfe1-main .ident "GCC: (GNU) 2.95.4 20010902 (Debian prerelease)" |
Output º¯¼ö´Â %edi·Î ÇÒ´çµÇ¾ú°í ¾î¶² inputµµ °ãÄ¡°Ô ÇÒ´çµÇÁö ¾Ê¾ÒÀ½À» ¾Ë ¼ö ÀÖ½À´Ï´Ù.