2.3. Output/Input List

Output°ú inputÀº "constraint" (variable)µéÀÇ ½°Ç¥·Î ±¸ºÐµÈ ¸®½ºÆ®·Î ±¸¼ºµË´Ï´Ù.

Constraint´Â ¾Æ·¡ÀÇ ¹®ÀÚµé°ú ¸î°¡Áö modifierµéÀÇ Á¶ÇÕÀ¸·Î Çã¿ëµÇ´Â operandÀÇ Á¾·ù¿Í ±× operand°¡ inline assembly¿¡¼­ ¾î¶»°Ô »ç¿ëµÇ´ÂÁö¸¦ ³ªÅ¸³À´Ï´Ù. ¾Æ·¡ÀÇ ¸®½ºÆ®´Â ¿ÏÀüÇÏÁö ¾Ê½À´Ï´Ù. Gcc ¸Þ´º¾óÀ» ÂüÁ¶Çϼ¼¿ä.

2.3.1. Constraints

2.3.1.1. Basic constraints

'm'

Architecture°¡ ÀϹÝÀûÀ¸·Î Áö¿øÇÏ´Â ¸ðµç addressing modeÁß Çϳª¸¦ »ç¿ëÇÏ´Â memory operand.

'r'

¹ü¿ë ·¹Áö½ºÅÍ operand.

'd', 'a', 'f', ...

·¹Áö½ºÅ͸¦ ÀûÁ¢ ÁöÁ¤ÇÏ´Â constraint. Architecture¸¶´Ù ´Ù¸¥ ¹®ÀÚµéÀ» Á¤ÀÇÇÕ´Ï´Ù. 'd', 'a', 'f'´Â 68000/68020¿¡¼­ ¾²´Â ¹®ÀÚµéÀÔ´Ï´Ù.

'i'

Á¤¼ö immediate operand. AssembleÇÒ ¶§°¡ µÇ¾î¾ß ¾Ë ¼ö ÀÖ´Â symbol°ª(ÁÖ¼Ò)µéµµ ÇØ´çµË´Ï´Ù.

'n'

°ªÀ» Á¤È®È÷ ¾Ë°í ÀÖ´Â Á¤¼ö. Symbol°ªµéÀº ÇØ´çµÇÁö ¾Ê½À´Ï´Ù.

'I', 'J', 'K', ... 'P'

¹Ì¸® Á¤ÇØÁø ¹üÀ§¾ÈÀÇ Á¤¼ö immediate operand. ¿¹¸¦ µé¾î 68000¿¡¼­ 'I'´Â 1¿¡¼­ 8»çÀÌÀÇ immediate operand¸¦ ¶æÇϸç shift operationÀÇ shift cound·Î ¾²ÀÔ´Ï´Ù.

'E'

Compling machine°ú target machineÀÇ floating Ç¥Çö ¹æ½ÄÀÌ °°À» ¶§ immediate floating operand¸¦ Çã¿ëÇÕ´Ï´Ù.

'F'

Immediate floating operand.

'G', 'H'

Machine¿¡ µû¶ó Á¤ÀǵǴ ƯÁ¤ÇÑ ¹üÀ§³»ÀÇ immediate floating point operand.

'g'

¹ü¿ë ·¹Áö½ºÅÍ, memory, immediate operand Áß ¹«¾ùÀÌ¶óµµ µË´Ï´Ù.

'X'

¾î¶°ÇÑ operand¶óµµ Çã¿ëÇÕ´Ï´Ù.

'p'

À¯È¿ÇÑ ÁÖ¼Ò°¡ Çã¿ëµË´Ï´Ù. Load address, push addressµîÀÇ instruction¿¡ ¾²ÀÔ´Ï´Ù.

'Q', 'R', 'S', ... 'U'

Machine-dependent.

2.3.1.2. i386 specific

'q'

a, b, c, or d register

'A'

a, or d register (for 64-bit ints)

'f'

Floating point register

't'

First (top of stack) floating point register

'u'

Second floating point register

'a'

a register

'b'

b register

'c'

c register

'd'

d register

'D'

di register

'S'

si register

'I'

Constant in range 0 to 31 (for 32bit shifts)

'J'

Constant in range 0 to 63 (for 64bit shifts)

'K'

0xff

'L'

0xffff

'M'

0, 1, 2, or 3 (shifts for lea instruction)

'N'

Constant in range 0 to 255 (for out instruction)

'G'

Standard 80387 floating point constant

2.3.1.3. Modifiers

Constraint modifierµéÀº ±× º¯¼ö°¡ ¾î¶»°Ô »ç¿ëµÇ´Â Áö¸¦ compiler¿¡°Ô ¾Ë·ÁÁÝ´Ï´Ù. ¾Æ·¡ÀÇ ¸®½ºÆ®´Â ¿ÏÀüÇÏÁö ¾Ê½À´Ï´Ù. Gcc ¸Þ´º¾óÀ» ÂüÁ¶Çϼ¼¿ä.

'='

º¯¼öÀÇ °ªÀÌ ¹Ù²ñÀ» ³ªÅ¸³À´Ï´Ù. Outputµé¿¡ ´ëÇØ¼­´Â ÀÌ modifier°¡ ¹Ýµå½Ã ÁöÁ¤µÇ¾î ÀÖ¾î¾ß ÇÕ´Ï´Ù.

'&'

Early clobber. ´ÙÀ½ Àý¿¡¼­ ÀÚ¼¼È÷ ¼³¸íÇϰڽÀ´Ï´Ù.

2.3.2. 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µµ °ãÄ¡°Ô ÇÒ´çµÇÁö ¾Ê¾ÒÀ½À» ¾Ë ¼ö ÀÖ½À´Ï´Ù.