2009年4月28日火曜日

20090421のhomework

1. This week we have talked about system calls. Take your "Hello, world" program from last week and produce the assembler output from the compiler. Post the assembler file on your blog.
・the assembler file
1 .file "hello.c"
2 .section .rodata
3 .LC0:
4 .string "Hello, World!\n"
5 .text
6 .p2align 2,,3
7 .globl main
8 .type main, @function
9 main:
10 pushl %ebp
11 movl %esp, %ebp
12 subl $8, %esp
13 andl $-16, %esp
14 movl $0, %eax
15 addl $15, %eax
16 addl $15, %eax
17 shrl $4, %eax
18 sall $4, %eax
19 subl %eax, %esp
20 subl $12, %esp
21 pushl $.LC0
22 call printf
23 addl $16, %esp
24 movl $0, %eax
25 leave
26 ret
27 .size main, .-main
28 .ident "GCC: (GNU) 3.4.6 [FreeBSD] 20060305"

a. "printf" is the instruction that calls the string output function.
it is a library function.
printf はソフト割り込みをかけていないため
b.
pushl $.LC0. 1個

c. "call printf"

2.
Unfortunately, even "Hello, world" is a little bit complicated. Take the following even shorter program and repeat the above exercise.

1 .file "123.c"
2 .section .rodata
3 .LC0:
4 .string "123"
5 .text
6 .p2align 2,,3
7 .globl main
8 .type main, @function
9 main:
10 pushl %ebp
11 movl %esp, %ebp
12 subl $8, %esp
13 andl $-16, %esp
14 movl $0, %eax
15 addl $15, %eax
16 addl $15, %eax
17 shrl $4, %eax
18 sall $4, %eax
19 subl %eax, %esp
20 movl $.LC0, -4(%ebp)
21 subl $4, %esp
22 pushl $3
23 pushl -4(%ebp)
24 pushl $1
25 call write
26 addl $16, %esp
27 movl $0, %eax
28 leave
29 ret
30 .size main, .-main
31 .ident "GCC: (GNU) 3.4.6 [FreeBSD] 20060305"

a. "write". it is a system call.
b. 3個

3.
Find a list of all of the system calls on the OS of your choice, and post it (or a link) on your blog. How many are there?

319個
http://d.hatena.ne.jp/toshi_hirasawa/20081105/1225885030

4.How long did it take you to complete this homework?

for 1 hour.

1 件のコメント:

  1. As we discussed in class, you found the *call* instruction, but not the interrupt that traps into the kernel. What happens when you step into the write function? That should be a "wrapper" function that leads to the "int" instruction.

    Score: 9/10

    返信削除