Homework 1
Homework 1
Homework 1
Assigned: Thursday September 5th
Due: @11:55PM Saturday, September 21st
1. Submit a pdf of your typed or handwritten homework on Gradescope. You should have
received an email inviting you to the Gradescope course. If you have not, please go to
www.gradescope.com, register for an account using your university email address (if
necessary), then add yourself to this course using the entry code M4D4D4.
2. Your answers should be neat, clearly marked, and concise. Typed work is
recommended, but not required unless otherwise stated.. Show all your work, and state any
special or non-obvious assumptions you make.
3. You may discuss your solution methods with other students, but the solutions you
submit must be your own.
4. Note that the last question is turned in separately and can be done in a group of up to 3
students. The group should only provide one submission for that problem. Read the directions
carefully for how to turn in that problem.
5. Late Homework Policy If your homework is less than 24 hours late, the grade is
reduced by 50%. Homeworks later than 24 hours will not be accepted.
i. 35(decimal)
iv. 13 (base 8)
b. (6 points, 3 each) Convert the following 16-bit binary 2’s complement numbers to
decimal.
c. (6 points, 2 each) Convert the following 16-bit binary numbers to hex: (Make sure you
have a solid understanding of these conversions, it will make future homeworks and
exams much easier )
b) (3 points) From part a, what is the resulting binary value in register X7? Please only
write the last 8 bits of the number.
Translate the following LC2K instructions from assembly to machine code. (Express your
answers in hexadecimal.)
lw 0 5 5 comment
lw 0 3 4 loop beq 3 4
End
add 6 2 2 beq 0 0
loop noop 65 (Think about how that 65 is
treated...)
End halt
Problem 4 (10 points)
For problem 4 follow the C/C++ order of operations. All variables and arrays are initialized. You
may not modify other registers.
Convert the following C code to 4 lines of LC2K assembly, use register 5 for computing the
displacement needed for Blue[a], register 6 for storing Blue[a], and register 7 for storing Blue
[a]+b.
Go[12] = Blue[a] + b;
c. (10 points) Explain how “Moore’s law” and “Dennard scaling” have historically impacted
the advancement of computers. Explain how these things are now changing. Your
answer should be between 150-250 words. You must type your explanation.
Group Problem
Student 3 Uniqname_________________
A now ex-coworker of yours wrote a function Find() and left a few comments, but very limited
documentation. You know that the function takes two arguments. The first is a pointer to an
array (passed in r1) and the second is the number of elements in the array (passed in r2). The
return value is found in r5. Answer the questions on the following page.
lw 0 1 ArrayS
lw 0 2 Num lw
0 3 Fcall jalr
3 7
halt
Find lw 0 6 NegOne // r6=-1 add 0
2 5 // r5=Num Top add 2 6 2
// Decrement Num add 1 2 4 // 4 is
address lw 4 3 0 // ld array element
beq 3 0 skip // is element 0? add
5 6 5 // if not sub 1 skip beq 0 2
Done // if Num=0 we are done beq 0 0 Top
// next iteration
Done jalr 7 3 // return
Zero .fill 0
NegOne .fill -1
Fcall .fill Find
ArrayS .fill Array
Num .fill 8
Array .fill 0
.fill 1
.fill 1
.fill 2222
.fill 0
.fill 777
.fill 0
.fill 1
.fill -5
Group Assignment Questions (35 points)
a) How many times will the line with the label “Find” get executed during this program? [3
Points]
_____________
_____________
_____________
d) In 10 words or less, describe what the return value of the function is in terms of the
array. Your answer should be something like “returns the maximum value in the array”.
[5 Points]
f) What did each member of your group find to be the most interesting part of the above
video? (You’ll get full points on this question as long as there is a couple of
sentences from each student that mentions something actually in the video).
[3 points]