1
+
2
+ <!-- saved from url=(0051)http://csl.yale.edu/~rajit/classes/eeng348/lab1.php -->
3
+ < html > < head > < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 ">
4
+ < title > EENG 348/CPSC 338: Digital Systems</ title >
5
+ < link rel ="stylesheet " href ="./spec_files/std.css ">
6
+ < link rel ="stylesheet " href ="./spec_files/default.css ">
7
+ < script src ="./spec_files/highlight.pack.js "> </ script >
8
+ < script > hljs . initHighlightingOnLoad ( ) ; </ script >
9
+ < style > body { overflow-y : scroll; } </ style >
10
+ < style > .alttable tr : nth-child (odd) { background : # dfefff ; } .alttable tr : nth-child (even) { background : # ffffff ; } .alttable { border-spacing : 0 10px ; } .alttable td { padding : 5px ; } </ style >
11
+ </ head >
12
+ < body bgcolor ="#ffffff " fgcolor ="#000000 ">
13
+ < table width ="100% ">
14
+ < tbody > < tr >
15
+ < td width ="3% "> </ td >
16
+ < td width ="94% " align ="center "> < table width ="100% "> < tbody > < tr > < td width ="100% "> < center >
17
+ < table border ="0 " width ="100% ">
18
+ < tbody > < tr >
19
+ < td align ="right " valign ="middle ">
20
+ < a href ="http://csl.yale.edu/ "> < img src ="./spec_files/yaleseas.jpg " height ="75 " border ="0 "> </ a > </ td >
21
+ < td valign ="middle " width ="80% ">
22
+ < font face ="helvetica,arial ">
23
+ < center >
24
+ < font size ="+3 "> EENG 348/CPSC 338: Digital Systems</ font > < br > < font size ="+2 "> Yale University</ font >
25
+ </ center >
26
+ </ font > </ td >
27
+ < td align ="left " valign ="middle ">
28
+ < a href ="http://avlsi.csl.yale.edu/ "> < img src ="./spec_files/anew2.gif " width ="150 " border ="0 "> </ a > </ td >
29
+ </ tr >
30
+ </ tbody > </ table > < br > </ center >
31
+ </ td > </ tr > < tr > < td width ="100% ">
32
+ < table width ="100% "> < tbody > < tr > < td width ="90 " valign ="top "> < br >
33
+ < table >
34
+ < tbody > < tr > < td align ="right "> < b > < a href ="http://csl.yale.edu/~rajit/classes/eeng348/index.php "> < font size ="-1 "> Home</ font > </ a > </ b > </ td > </ tr >
35
+ < tr > < td align ="right "> < b > < a href ="http://www.piazza.com/class "> < font size ="-1 "> Discussions</ font > </ a > </ b > </ td > </ tr >
36
+ < tr > < td align ="right "> < b > < a href ="http://csl.yale.edu/~rajit/classes/eeng348/lectures.php "> < font size ="-1 "> Lectures</ font > </ a > </ b > </ td > </ tr >
37
+ < tr > < td align ="right "> < b > < a href ="http://csl.yale.edu/~rajit/classes/eeng348/labs.php "> < font size ="-1 "> Labs</ font > </ a > </ b > </ td > </ tr >
38
+ < tr > < td align ="right "> < b > < a href ="http://csl.yale.edu/~rajit/classes/eeng348/handouts.php "> < font size ="-1 "> Handouts</ font > </ a > </ b > </ td > </ tr >
39
+ < tr > < td align ="right "> < b > < a href ="http://csl.yale.edu/~rajit/classes/eeng348/policies.php "> < font size ="-1 "> Policies</ font > </ a > </ b > </ td > </ tr >
40
+ < tr > < td align ="right "> < b > < a href ="http://csl.yale.edu/~rajit/classes/eeng348/calendar.php "> < font size ="-1 "> Calendar</ font > </ a > </ b > </ td > </ tr >
41
+ < tr > < td align ="right "> < b > < a href ="http://canvas.yale.edu/ "> < font size ="-1 "> Canvas</ font > </ a > </ b > </ td > </ tr >
42
+ </ tbody > </ table >
43
+ </ td > < td width ="4 "> </ td > < td valign ="top ">
44
+ < h3 > Lab 1: Assembly language programming</ h3 >
45
+ < b > Due: Feb < strike > 2</ strike > 4, 11:59pm. Submit on Canvas.</ b > < br >
46
+ < b > Weight: 10%</ b >
47
+
48
+ < p > < b > Goal.</ b > The goal of this lab is to give you some experience
49
+ writing assembly language programs for the AVR microcontroller. To
50
+ successfully complete the lab, you will need to understand:
51
+
52
+ </ p > < ul >
53
+ < li > The AVR instruction set
54
+ </ li > < li > The Arduino programming environment (i.e. lab 0)
55
+ </ li > < li > Calling conventions
56
+ </ li > </ ul >
57
+ < p > </ p >
58
+
59
+ < table border ="0 " cellspacing ="4 " cellpadding ="2 " width ="100% ">
60
+ < tbody > < tr bgcolor ="#aaaacc " valign ="center "> < td > < b > Part 1: Getting started with assembly</ b > </ td >
61
+ </ tr >
62
+ </ tbody > </ table >
63
+
64
+ < p > To write assembly in the unmodified Arduino environment, we will
65
+ use a construct that is built into the C++ compiler that is invoked to
66
+ compile your program. We can mix assembly language and C++ directly by
67
+ using the "< code > asm</ code > " directive. The flavor we use is
68
+ sometimes called "< code > asm volatile</ code > ", and by using the
69
+ keyword "< code > volatile</ code > " we are telling the compiler not to
70
+ touch the assembly language sequence that has been specified--i.e. to
71
+ perform no optimizations.</ p >
72
+
73
+ < p > A template Arduino sketch for assembly language programming is
74
+ provided (< a href ="http://csl.yale.edu/~rajit/classes/eeng348/files/sketch_asm.zip "> zip file</ a > ). The
75
+ "< code > .ino</ code > " file contains the driver, which can be used to
76
+ output values using the serial monitor. The file that should contain
77
+ the assembly language is "< code > testasm.cpp</ code > ", which you can
78
+ edit with any text editor directly.</ p >
79
+
80
+ < p > The example sketch in the zip file ends with a loop that
81
+ continuously blinks the built-in LED on the Uno. This is just a simple
82
+ sanity check to make sure that your assembly language program ran
83
+ properly and didn't mess up the stack.</ p >
84
+
85
+ < p > For this part, write an assembly language program that adds two
86
+ numbers. The two numbers to be added are the unsigned 8-bit integers
87
+ "< code > a</ code > " and "< code > b</ code > " (see the
88
+ "< code > testasm</ code > " function), and the result should be a 16-bit
89
+ value corresponding to their sum. In this part, you will be saving and
90
+ restoring any register being modified (see the instructions in
91
+ < code > testasm</ code > function). (Hint: you will need to use the carry
92
+ flag.)</ p >
93
+
94
+ < table border ="0 " cellspacing ="4 " cellpadding ="2 " width ="100% ">
95
+ < tbody > < tr bgcolor ="#aaaacc " valign ="center "> < td > < b > Part 2: Procedures</ b > </ td >
96
+ </ tr >
97
+ </ tbody > </ table >
98
+
99
+ < p > Implement the following two functions in assembly, respecting all calling conventions.</ p >
100
+
101
+ < pre > < code class ="hljs cpp "> < span class ="hljs-function "> < span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> int</ span > < span class ="hljs-title "> sumval</ span > < span class ="hljs-params "> (< span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> char</ span > a, < span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> char</ span > b)</ span >
102
+ </ span > {
103
+ < span class ="hljs-keyword "> return</ span > a+b;
104
+ }
105
+
106
+ < span class ="hljs-function "> < span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> int</ span > < span class ="hljs-title "> diffval</ span > < span class ="hljs-params "> (< span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> char</ span > a, < span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> char</ span > b)</ span >
107
+ </ span > {
108
+ < span class ="hljs-keyword "> if</ span > (a > b) {
109
+ < span class ="hljs-keyword "> return</ span > a-b;
110
+ }
111
+ < span class ="hljs-keyword "> else</ span > {
112
+ < span class ="hljs-keyword "> return</ span > b-a;
113
+ }
114
+ }
115
+ </ code > </ pre >
116
+
117
+ < p >
118
+ Finally, the main program in assembly language should set the return
119
+ registers (< code > r25:r24</ code > , see the template) to the value
120
+ "< code > sumval(a,b)+diffval(a,b)</ code > ", using function calls to
121
+ invoke the two functions and combine their return values.</ p >
122
+
123
+ < table border ="0 " cellspacing ="4 " cellpadding ="2 " width ="100% ">
124
+ < tbody > < tr bgcolor ="#aaaacc " valign ="center "> < td > < b > Part 3: Recursion</ b > </ td >
125
+ </ tr >
126
+ </ tbody > </ table >
127
+
128
+ < p >
129
+ The < a href ="https://en.wikipedia.org/wiki/Fibonacci_number "> Fibonacci
130
+ sequence</ a > is defined by the recursion F< sub > 0</ sub > = 0,
131
+ F< sub > 1</ sub > = 1, and F< sub > n</ sub > = F< sub > n-1</ sub > +
132
+ F< sub > n-2</ sub > for n>1. A simple way to compute the nth Fibonacci
133
+ number is the following C program (which also returns zero for
134
+ negative arguments):</ p >
135
+
136
+ < pre > < code class ="hljs cpp "> < span class ="hljs-function "> < span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> int</ span > < span class ="hljs-title "> fib</ span > < span class ="hljs-params "> (< span class ="hljs-keyword "> unsigned</ span > < span class ="hljs-keyword "> char</ span > n)</ span >
137
+ </ span > {
138
+ < span class ="hljs-keyword "> if</ span > (n == < span class ="hljs-number "> 0</ span > ) < span class ="hljs-keyword "> return</ span > < span class ="hljs-number "> 0</ span > ;
139
+ < span class ="hljs-keyword "> if</ span > (n == < span class ="hljs-number "> 1</ span > ) < span class ="hljs-keyword "> return</ span > < span class ="hljs-number "> 1</ span > ;
140
+ < span class ="hljs-keyword "> return</ span > fib(n< span class ="hljs-number "> -1</ span > )+fib(n< span class ="hljs-number "> -2</ span > );
141
+ }
142
+ </ code > </ pre >
143
+
144
+ < p > Implement this recursive function using assembly language. Your
145
+ implementation < u > must use recursion</ u > . The result of the call to
146
+ < code > fib()</ code > should be displayed on the serial monitor. Your
147
+ program should be able to work for any Fibonacci number that can be
148
+ represented by an 8-bit value. Include your test cases in your
149
+ submission as well. Use the template from part 1 for this part. For
150
+ simplicity, you can simply ignore the second argument to the
151
+ function. For the more adventurous, feel free to modify the
152
+ "< code > asm</ code > " directive to only use one argument.</ p >
153
+
154
+
155
+ < table border ="0 " cellspacing ="4 " cellpadding ="2 " width ="100% ">
156
+ < tbody > < tr bgcolor ="#aaaacc " valign ="center "> < td > < b > What you have to submit</ b > </ td >
157
+ </ tr >
158
+ </ tbody > </ table >
159
+
160
+ < p > You should turn in three sketches, one for each part of the lab,
161
+ as a single zip file. The zip file should be submitted through Canvas,
162
+ with one submission per team. </ p >
163
+
164
+ < p > The zip file should contain three sketches,
165
+ "< code > sketch_part1</ code > ", "< code > sketch_part2</ code > ",
166
+ "< code > sketch_part3</ code > " that are folders containing the
167
+ "< code > .ino</ code > " file and the "< code > testasm.{cpp,h}</ code > "
168
+ files. Include a plain text file called "< code > README</ code > " as
169
+ part of your submission, where you can provide any information you
170
+ like to the teaching staff grading the lab.</ p >
171
+
172
+ < p > Please make sure your assembly language program is
173
+ well-commented. In particular, for any program that includes
174
+ functions, your comments should describe the stack layout (i.e. a
175
+ detailed description of the stack frame for each function).</ p >
176
+
177
+ < p >
178
+ The sketches should also include a reasonable set of test cases.
179
+ </ p >
180
+
181
+
182
+ </ td > </ tr > </ tbody > </ table > </ td > </ tr > < tr > < td width ="100% "> < br >
183
+ </ td > </ tr > </ tbody > </ table > </ td > < td width ="3% "> </ td >
184
+ </ tr >
185
+ </ tbody > </ table > < table noborder ="" cellpadding ="0 " cellspacing ="0 " width ="100% "> < tbody > < tr > < td > </ td > < td > </ td > </ tr > < tr bgcolor ="#00356b "> < td width ="2% "> </ td > < td width ="98% " align ="left "> < a href ="http://www.yale.edu/ "> < img src ="./spec_files/yale-white.png " alt ="Yale "> </ a > </ td > </ tr > </ tbody > </ table >
186
+ </ body > </ html >
0 commit comments