gas hello.S
GAS(Gnu Assembler)だ、ATTだ。
Intel方式になれている御方のために
1)オペランドは左から右に、インテルとは逆
2)レジスタ名の前に%をおく 例 %eax
3) イミディエーとの前には$をおく 例 $0x80
4) 各命令(ニーモニック)のは、オペランドサイズに応じた以下のサフィックスを
つける 例 movl
8bit b
16bit w
32bit l
64bit q
5) (%eax) ... C的にかくと*(ptr) あってる?
[hirasawa@ubunt1004-32-2 gcc-Programming-Kobo]$ cat hello.S .global _start _start: #ssize_t mywrite(int fd, const void *buf , size_t count) movl $msglen, %edx movl $msg, %ecx movl $1,%ebx movl $4,%eax int $0x80 #void exit(it status) movl %eax ,%ebx movl $1 ,%eax int $0x80 msg: .asciz "hello\n" msglen = . - msg
http://d.hatena.ne.jp/toshi_hirasawa/20120202/1328189742
[hirasawa@ubunt1004-32-2 gcc-Programming-Kobo]$ as hello.S -a GAS LISTING hello.S page 1 1 .global _start 2 _start: 3 4 #ssize_t mywrite(int fd, const void *buf , size_t count) 5 0000 BA070000 movl $msglen, %edx 5 00 6 0005 B91F0000 movl $msg, %ecx 6 00 7 000a BB010000 movl $1,%ebx 7 00 8 000f B8040000 movl $4,%eax 8 00 9 0014 CD80 int $0x80 10 11 #void exit(it status) 12 0016 89C3 movl %eax ,%ebx 13 0018 B8010000 movl $1 ,%eax 13 00 14 001d CD80 int $0x80 15 16 msg: 17 001f 68656C6C .asciz "hello\n" 17 6F0A00 18 msglen = . - msg GAS LISTING hello.S page 2 DEFINED SYMBOLS hello.S:2 .text:0000000000000000 _start *ABS*:0000000000000007 msglen hello.S:16 .text:000000000000001f msg NO UNDEFINED SYMBOLS [hirasawa@ubunt1004-32-2 gcc-Programming-Kobo]$
as hello.S -aだとa.outが生成され、
gcc -v -save-temps hello.Sだと(ただしくは gcc -v -save-temps -c -o hello.o hello.Sがいいかな。)
hello.sとhello.oが生成される。
hello.Sとhello.sの違いはなんなん?とかちょっと疑問にわきました。
そのうちしらべましょ。
vちなみにa.outとhello.oの中身は同一となりました。