コンパイラによってはintもcharも同じ?

最近アセンブラを弄ってて、気がついたのでメモメモ

アライメントは実行時でなくて、コンパイルで起きるみたい

  • コンパイル前
int sub01(char i, char j)
{
    i += j;
    return i;
}

void main()
{
    char i = 10;
    char j = 20;
    i = sub01(i, j);
}
  • コンパイルしたところ。

8bitのデータも32bitのデータとしてコンパイルされてます。

つまり、32bitコンパイラではcharを使っても意味が無い。?

.file	"test.c"
.text
.globl sub01
.type	sub01, @function
sub01:
pushl	%ebp
movl	%esp, %ebp
subl	$8, %esp
movl	8(%ebp), %edx
movl	12(%ebp), %eax
movb	%dl, -4(%ebp)
movb	%al, -8(%ebp)
movzbl	-4(%ebp), %edx
movzbl	-8(%ebp), %eax
leal	(%edx,%eax), %eax
movb	%al, -4(%ebp)
movsbl	-4(%ebp),%eax
leave
ret
.size	sub01, .-sub01

.globl main
.type	main, @function
main:
pushl	%ebp
movl	%esp, %ebp
subl	$24, %esp
movb	$10, -1(%ebp)
movb	$20, -2(%ebp)
movsbl	-2(%ebp),%edx
movsbl	-1(%ebp),%eax
movl	%edx, 4(%esp)
movl	%eax, (%esp)
call	sub01
movb	%al, -1(%ebp)
leave
ret
.size	main, .-main
.ident	"GCC: (Ubuntu 4.4.1-4ubuntu9) 4.4.1"
.section	.note.GNU-stack,"",@progbits

コンパイラはGCCです。
間違っていたらスイマセンm。。

投稿者:

「コンパイラによってはintもcharも同じ?」への19件のフィードバック

  1. I want to voice my respect for your generosity supporting men who require help with your niche. Your very own dedication to getting the message all around came to be extraordinarily important and have truly empowered those much like me to arrive at their desired goals. This important instruction means a whole lot a person like me and a whole lot more to my office colleagues. Best wishes; from each one of us.

  2. Thank you for sharing superb informations. Your web site is so cool. I’m impressed by the details that you have on this website. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found simply the information I already searched all over the place and just could not come across. What a perfect web site.

  3. Based on my observation, after a in foreclosure home is available at an auction, it is common to the borrower in order to still have any remaining balance on the loan. There are many loan companies who seek to have all charges and liens paid back by the following buyer. Even so, depending on particular programs, polices, and state laws and regulations there may be several loans which are not easily solved through the transfer of lending options. Therefore, the responsibility still lies on the debtor that has obtained his or her property in foreclosure. Thank you sharing your thinking on this weblog.

  4. Hello there! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains. If you know of any please share. Appreciate it!

  5. You can certainly see your enthusiasm in the work you write. The sector hopes for more passionate writers like you who are not afraid to mention how they believe. All the time go after your heart. “Experience is a good school, but the fees are high.” by Heinrich Heine.

  6. I couldn’t discover too much various information on this piece of contents, so it was great to find his one. I will get back again to look through the other publications that you have next time.

  7. My wife and i felt quite happy that Chris managed to do his inquiry through the entire ideas he obtained through the site. It’s not at all simplistic to just possibly be offering things which the rest might have been trying to sell. Therefore we see we have the website owner to appreciate for that. The most important illustrations you’ve made, the simple blog menu, the relationships you aid to foster – it’s got many powerful, and it’s really assisting our son and the family do think this theme is cool, and that’s extremely indispensable. Many thanks for all!

  8. I am not sure where you’re getting your information, but great topic. I needs to spend some time learning more or understanding more. Thanks for great information I was looking for this information for my mission.

  9. This domain seems to get a good ammount of visitors. How do you advertise it? It offers a nice unique spin on things. I guess having something useful or substantial to give info on is the most important factor.

コメントを残す

メールアドレスが公開されることはありません。