Skip to content

Commit

Permalink
solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
huppy309 committed Mar 29, 2017
0 parents commit 83916bb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Recitation 8 - Solutions
-----

The answers to the questions are:

1) 'x' starts in register $rdi and gets returned in $rax in function addone2. It is in memory location 0x7fffffffdfe8 in addone (The address value in addone may be slightly different depending on the student's machine but I have asked them to send screenshots of their work. As long as the address resembles the value mentioned here that is good enough for full credit)

2) Instructions corresponding to line 12 are:

```
12 (*x)++;
=> 0x0000000000400562 <addone+0>: 48 8b 07 mov (%rdi),%rax
0x0000000000400565 <addone+3>: 48 83 c0 01 add $0x1,%rax
0x0000000000400569 <addone+7>: 48 89 07 mov %rax,(%rdi)
```

3) The instruction that causes the segmentation fault is:

```
=> 0x0000000000400562 <addone+0>: 48 8b 07 mov (%rdi),%rax
```

The variable x holds the value 2, and x is a long *. This will clearly led to a segmentation fault when x is dereferenced. The specific instruction that does this is the one marked with the arrow: mov (%rdi),%rax. Trying to take the value at the address given by register %rdi, or trying to dereference x, causes the segmentation fault (line 27 of the source code to see the function call).

0 comments on commit 83916bb

Please sign in to comment.