おひさでーす 投稿者:志穂 投稿日:2002/12/13(Fri) 18:07 No.111 | |
|
.comm x,4,4 .comm y,4,4 .comm z,4,4
$ cat main.c int x,y,z; int main(void){ x=2; y=3; z=x+y; } $ cat main.s .file "main.c" .version "01.01" gcc2_compiled.: .text .align 4 .globl main .type main,@function main: pushl %ebp movl %esp, %ebp movl $2, x movl $3, y movl y, %eax addl x, %eax movl %eax, z popl %ebp ret .Lfe1: .size main,.Lfe1-main .comm x,4,4 .comm y,4,4 .comm z,4,4 .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-85)"
さいごの .comm x,4,4 .comm y,4,4 .comm z,4,4 なんですが、
4バイト分メモリ領域を確保せよってのは わかるんですが、
最後の4はなにを意味してるんでしょう? コンパイラ特有のもの?
|
| Re: おひさでーす jun - 2002/12/13(Fri) 22:15 No.112 | |
|
|
まあ、コンパイラというかアセンブラ特有のものとです。 アラインメントを調整しています。
as.infoによると: ------------------------------------------------------- When using ELF, the `.comm' directive takes an optional third argument. This is the desired alignment of the symbol, specified as a byte boundary (for example, an alignment of 16 means that the least significant 4 bits of the address should be zero). The alignment must be an absolute expression, and it must be a power of two. If `ld' allocates uninitialized memory for the common symbol, it will use the alignment when placing the symbol. If no alignment is specified, `as' will set the alignment to the largest power of two less than or equal to the size of the symbol, up to a maximum of 16. ------------------------------------------------------- というわけで、2^4=16バイトでアラインしています。
インテル系のCPUは奇数アドレスを先頭とするメモリアクセス が可能ですが、8バイトや16バイトというキリのいいアドレス からアクセスすると速くなるためです。
|
|