summaryrefslogtreecommitdiff
path: root/assignments/3-solution.md
blob: d886473e98a57349fc302b6d258e97d4f53ef8cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# COMP-200: Intro to Computer Systems
## Assignment 3
### mo khan - 3431709

Choose ONE exercise each from Chapters 6, 7, and 8

Chapter 6:

> 13. Write a complete assembly language program (including all necessary
> pseudo-ops) that reads in a series of integers, one at a time, and outputs
> the largest and smallest values. The input will consist of a list of integer
> values

```assembly
!include assignments/3/max_min.s
```

<!--
I wrote the following C code and then used the GNU C Compiler to convert the C
code into Assembly code for my machine. Below is the C code, compiler command,
and final assembly code.

main.c
```c
!include assignments/3/main.c
```

bash
```bash
$ gcc -S -fverbose-asm -02 main.c
```

main.s
```assembly
!include assignments/3/main.s
```
-->

Chapter 7:

> 16. Given the following diagram, where the numbers represent the time delays across a link:

>  a. How many simple paths (those that do not repeat a node) are there from node A to G?
  ```plaintext
    A<->B: 5
    A<->D: 6
    A<->F: 3
    B<->C: 4
    B<->E: 2
    C<->D: 3
    C<->E: 1
    C<->G: 2
    D<->E: 1
    F<->G: 8
  ```

  There are 7 simple paths

  ```plaintext
  | Path        |
  | ----        |
  | a,b,c,g     |
  | a,b,e,c,g   |
  | a,b,e,d,c,g |
  | a,d,c,g     |
  | a,d,e,b,c,g |
  | a,d,e,c,g   |
  | a,f,g       |
  ```

>  b. What is the shortest path from node A to node G? What is the overall delay?

  The shortest path has a distance of 10.
  The overall delay is 11 (`((11 + 10 + 13 + 11 + 15 + 10 + 11)/7) = 11`).


  ```plaintext
  | Path        | Total Distance |
  | ----        | -------------- |
  | a,b,c,g     | 5+4+2 = 11     |
  | a,b,e,c,g   | 5+2+1+2 = 10   |
  | a,b,e,d,c,g | 5+2+1+3+2 = 13 |
  | a,d,c,g     | 6+3+2 = 11     |
  | a,d,e,b,c,g | 6+1+2+4+2 = 15 |
  | a,d,e,c,g   | 6+1+1+2 = 10   |
  | a,f,g       | 3+8 = 11       |
  ```

>  c. If node E fails, does that change the shortest path? If so, what is the new shortest path?

  Yes, if node E fails then there are 3 simple paths remaining with the shortest path having a distance of 11.

  ```plaintext
    A<->B: 5
    A<->D: 6
    A<->F: 3
    B<->C: 4
    C<->D: 3
    C<->G: 2
    F<->G: 8
  ```

  ```plaintext
  | Path        | Total Distance |
  | ----        | -------------- |
  | a,b,c,g     | 5+4+2 = 11     |
  | a,d,c,g     | 6+3+2 = 11     |
  | a,f,g       | 3+8 = 11       |
  ```

The following code can be used to prove these results:

```ruby
!include assignments/3/graph.rb
```

Chapter 8:

> 9. Using a Caesar cipher with s = 5, decode the received message RTAJ TZY FY IF

The following code can be used to decipher the Caesar cipher.

```ruby
!include assignments/3/caesar.rb
```

The plaintext is `MOVE OUT AT DAWN`.

```bash
$ ruby caesar.rb
# Caesar Cipher

| --------------- | --------------------------------------------------- |
| Plain Alphabet  | A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z |
| Cipher Alphabet | F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A,B,C,D,E |
| --------------- | --------------------------------------------------- |
| Key             | 5                                                   |
| Ciphertext      | RTAJ TZY FY IFBS                                    |
| Plaintext       | MOVE OUT AT DAWN                                    |
```

References:

* https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
* https://cs.lmu.edu/~ray/notes/gasexamples/
* https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_7.html