changeset 0:70f82040dbc7 default tip

bit.c sizeOfWord.c
author nobuyasu
date Tue, 15 Feb 2011 11:25:07 +0900
parents
children
files bit.c bit.s sizeOfWord.c
diffstat 3 files changed, 133 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bit.c	Tue Feb 15 11:25:07 2011 +0900
@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+struct
+{
+  char ans0;
+  char ans1: 1;
+  char ans2: 2;
+  char ans3;
+  char ans4: 3;
+}test;
+
+int main()
+{
+  test.ans0 = 0;
+  test.ans1 = 0;
+  test.ans2 = 2;
+  test.ans3 = 1;
+  test.ans4 = 3;
+  int i;
+  char *ptr = &test;
+  for(i=0; i<3; i++){
+    printf("%x\n",ptr+i);
+  }
+  printf("%x\n",&test.ans0);
+  //  printf("%x\n",&test.ans1);
+
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bit.s	Tue Feb 15 11:25:07 2011 +0900
@@ -0,0 +1,97 @@
+	.cstring
+LC0:
+	.ascii "%x\12\0"
+	.text
+.globl _main
+_main:
+LFB3:
+	pushq	%rbp
+LCFI0:
+	movq	%rsp, %rbp
+LCFI1:
+	subq	$16, %rsp
+LCFI2:
+	movq	_test@GOTPCREL(%rip), %rax
+	movb	$0, (%rax)
+	movq	_test@GOTPCREL(%rip), %rdx
+	movzbl	1(%rdx), %eax
+	andl	$-2, %eax
+	movb	%al, 1(%rdx)
+	movq	_test@GOTPCREL(%rip), %rax
+	movb	$7, 2(%rax)
+	movq	_test@GOTPCREL(%rip), %rax
+	movq	%rax, -16(%rbp)
+	movl	$0, -4(%rbp)
+	jmp	L2
+L3:
+	movl	-4(%rbp), %eax
+	cltq
+	movq	%rax, %rsi
+	addq	-16(%rbp), %rsi
+	leaq	LC0(%rip), %rdi
+	movl	$0, %eax
+	call	_printf
+	incl	-4(%rbp)
+L2:
+	cmpl	$2, -4(%rbp)
+	jle	L3
+	movq	_test@GOTPCREL(%rip), %rsi
+	leaq	LC0(%rip), %rdi
+	movl	$0, %eax
+	call	_printf
+	movq	_test@GOTPCREL(%rip), %rax
+	leaq	2(%rax), %rsi
+	leaq	LC0(%rip), %rdi
+	movl	$0, %eax
+	call	_printf
+	movl	$0, %eax
+	leave
+	ret
+LFE3:
+.comm _test,3,0
+	.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
+EH_frame1:
+	.set L$set$0,LECIE1-LSCIE1
+	.long L$set$0
+LSCIE1:
+	.long	0x0
+	.byte	0x1
+	.ascii "zR\0"
+	.byte	0x1
+	.byte	0x78
+	.byte	0x10
+	.byte	0x1
+	.byte	0x10
+	.byte	0xc
+	.byte	0x7
+	.byte	0x8
+	.byte	0x90
+	.byte	0x1
+	.align 3
+LECIE1:
+.globl _main.eh
+_main.eh:
+LSFDE1:
+	.set L$set$1,LEFDE1-LASFDE1
+	.long L$set$1
+LASFDE1:
+	.long	LASFDE1-EH_frame1
+	.quad	LFB3-.
+	.set L$set$2,LFE3-LFB3
+	.quad L$set$2
+	.byte	0x0
+	.byte	0x4
+	.set L$set$3,LCFI0-LFB3
+	.long L$set$3
+	.byte	0xe
+	.byte	0x10
+	.byte	0x86
+	.byte	0x2
+	.byte	0x4
+	.set L$set$4,LCFI1-LCFI0
+	.long L$set$4
+	.byte	0xd
+	.byte	0x6
+	.align 3
+LEFDE1:
+	.subsections_via_symbols
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sizeOfWord.c	Tue Feb 15 11:25:07 2011 +0900
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+  printf("size of int : %ld\n",sizeof(int));
+  printf("size of char : %ld\n",sizeof(char));
+  return 0;
+}