forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathvecsum.s.html
48 lines (43 loc) · 3.31 KB
/
vecsum.s.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>vecsum.s</title>
</head>
<body style="background-color:white">
<pre><i><span style="color:#9A1900">; vecsum.s</span></i>
<i><span style="color:#9A1900">;</span></i>
<i><span style="color:#9A1900">; Purpose : This file contains the implementation of the function</span></i>
<i><span style="color:#9A1900">; vecsum, which adds up a vector of integers.</span></i>
<i><span style="color:#9A1900">;</span></i>
<i><span style="color:#9A1900">; Parameter 1 (in rdi) is the starting address of a sequence of 64-bit longs</span></i>
<i><span style="color:#9A1900">; Parameter 2 (in rsi) is the number of integers in the sequence</span></i>
<i><span style="color:#9A1900">; Return value is a long that is the sum of the integers in the sequence</span></i>
<i><span style="color:#9A1900">;</span></i>
global vecsum
section <span style="color:#990000">.</span>text
<b><span style="color:#000080">vecsum:</span></b>
<i><span style="color:#9A1900">; Standard prologue: we do not have to create any local</span></i>
<i><span style="color:#9A1900">; variables (those values will be kept in registers), and </span></i>
<i><span style="color:#9A1900">; we are not using any callee-saved registers.</span></i>
<i><span style="color:#9A1900">; Subroutine body:</span></i>
<b><span style="color:#0000FF">xor</span></b> rax<span style="color:#990000">,</span> rax <i><span style="color:#9A1900">; zero out the return register</span></i>
<b><span style="color:#0000FF">xor</span></b> r<span style="color:#993399">10</span><span style="color:#990000">,</span> r<span style="color:#993399">10</span> <i><span style="color:#9A1900">; zero out the counter i</span></i>
<b><span style="color:#000080">start:</span></b>
<b><span style="color:#0000FF">cmp</span></b> r<span style="color:#993399">10</span><span style="color:#990000">,</span> rsi <i><span style="color:#9A1900">; does i == n?</span></i>
<b><span style="color:#0000FF">je</span></b> done <i><span style="color:#9A1900">; if so, we are done with the loop</span></i>
<b><span style="color:#0000FF">add</span></b> rax<span style="color:#990000">,</span> <span style="color:#990000">[</span>rdi<span style="color:#990000">+</span><span style="color:#993399">8</span><span style="color:#990000">*</span>r<span style="color:#993399">10</span><span style="color:#990000">]</span> <i><span style="color:#9A1900">; add a[i] to rax</span></i>
<b><span style="color:#0000FF">inc</span></b> r<span style="color:#993399">10</span> <i><span style="color:#9A1900">; increment our counter i</span></i>
<b><span style="color:#0000FF">jmp</span></b> start <i><span style="color:#9A1900">; we are done with this loop iteration</span></i>
<b><span style="color:#000080">done:</span></b>
<i><span style="color:#9A1900">; Standard epilogue: the return value is already in rax, we</span></i>
<i><span style="color:#9A1900">; do not have any callee-saved registers to restore, and we do not</span></i>
<i><span style="color:#9A1900">; have any local variables to deallocate, so all we do is return</span></i>
<b><span style="color:#0000FF">ret</span></b>
</pre>
</body>
</html>