0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cの配列はメモリでこうなる ― intとcharの大きさをARMアセンブリで確

Last updated at Posted at 2025-09-04

int配列は4バイトずつ、char配列は1バイトずつずらしながら値を代入している。
x86と同じでintは4バイト、charは1バイトということが分かった。

gcc -O0 -S test.c -o test.s
test.c
int main(){
  int a[4];
  a[0]=11;
  a[1]=22;
  a[2]=33;
  a[3]=44;

  char b[4];
  b[0]=55;
  b[1]=66;
  b[2]=77;
  b[3]=88;
  return 0;
}
test.s
main:
	push	{r7}
	sub	sp, sp, #28
	add	r7, sp, #0
	movs	r3, #11
	str	r3, [r7, #8]
	movs	r3, #22
	str	r3, [r7, #12]
	movs	r3, #33
	str	r3, [r7, #16]
	movs	r3, #44
	str	r3, [r7, #20]
	movs	r3, #55
	strb	r3, [r7, #4]
	movs	r3, #66
	strb	r3, [r7, #5]
	movs	r3, #77
	strb	r3, [r7, #6]
	movs	r3, #88
	strb	r3, [r7, #7]
	movs	r3, #0
	mov	r0, r3
	adds	r7, r7, #28
	mov	sp, r7
	ldr	r7, [sp], #4
	bx	lr
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?