2022/12/12 20:14 Project 4
https://canvas.wisc.edu/courses/323092/assignments/1750056?return_to=https%3A%2F%2Fcanvas.wisc.edu%2Fcalendar%23view_name%3Dmonth%26view_… 1/4
Copyright By PowCoder代写 加微信 powcoder
Due Monday by 10pm Points 33 Submitting a file upload File Types txt
Available Nov 22 at 1pm – Dec 14 at 10pm
Start Assignment
Projects may be done in a pair or individually and in accordance with the Projects: Information
and Policies (https://canvas.wisc.edu/courses/323092/pages/projects-information-and-policies) .
Collatz: Project Description
For this project, you are to use subroutines to complete the LC-3 assembly language program
template that we provide.
The Collatz Conjecture, also known as the 3x+1 conjecture, is a popular math conjecture that’s not
yet proven (see Wiki (https://en.wikipedia.org/wiki/Collatz_conjecture) online tool
(https://www.dcode.fr/collatz-conjecture?__r=1.4de41443d5feb5be59702c5c119ff869)
First, download the program template: HERE
(https://canvas.wisc.edu/courses/323092/files/29261166/download)
(https://canvas.wisc.edu/courses/323092/files/29261166/download?download_frd=1) . Read the
documentation in that text file after reading this page.
Subroutines You’re to Complete
Complete the subroutines in the order listed below.
Note the COLLATZ_STEPS subroutine is to be completed last since it uses subroutines
MUL3ADD1 and DIVIDEBY2.
You must use the registers specified in the program template for each subroutine’s
argument and return value.
This ensures your code will work with our main program and testers.
Be careful to properly handle the return address in R7 or else your program will fail!
Properly preserve the register R0 wherever required or else the test harness will fail!
1. MUL3ADD1 subroutine (7 pts)
(6 pts) Implement the subroutine MUL3ADD1 as specified in the program template.
The subroutine should return the result (3 * A) + 1 given A as the input.
(1 pt) Properly preserve the register values as needed.
https://canvas.wisc.edu/courses/323092/pages/projects-information-and-policies
https://en.wikipedia.org/wiki/Collatz_conjecture
https://www.dcode.fr/collatz-conjecture?__r=1.4de41443d5feb5be59702c5c119ff869
https://canvas.wisc.edu/courses/323092/files/29261166/download
https://canvas.wisc.edu/courses/323092/files/29261166/download?download_frd=1
2022/12/12 20:14 Project 4
https://canvas.wisc.edu/courses/323092/assignments/1750056?return_to=https%3A%2F%2Fcanvas.wisc.edu%2Fcalendar%23view_name%3Dmonth%26view_… 2/4
2. DIVIDEBY2 subroutine (11 pts)
(10 pts) Implement the subroutine DIVIDEBY2 as specified in the program template.
The subroutine returns the RESULT of N / 2 given an even positive integer N as input
and using the following algorithm:
RESULT = 0
while N >= 2
subtract 2 from N
increment RESULT by 1
(1 pt) Properly preserve the register values as needed.
3. COLLATZ_STEPS subroutine (11 pts)
(10 pts) Implement the subroutine COLLATZ_STEPS as specified in the program template.
This subroutine calculates the number of STEPS required to transform a positive integer X to 1
using the following algorithm:
while X is not equal to 1:
if X is even -> decrease X to X/2
if X is odd -> increase X to 3 * X + 1
increment STEPS by 1
You are to use the MUL3ADD1 and DIVIDEBY2 subroutines in this subroutine.
(1 pt) Properly preserve the register values as needed.
Code We’ve Provided
We provide a program template file for you to complete. Please refer to the Project Description
section above for the link to download the program template. The template file is structured as
Header comments that you need to fill in and boxes you need to mark.
Descriptions of each subroutine, followed by a placeholder where you need to implement the
subroutine’s LC-3 assembly code. You are to implement each subroutine only within its
designated regions.
Three helper subroutines (PRINT_DIGIT, PRINT_INT, COLLATZ) are provided to help you check
your code.
The main section includes tester subroutines to test the subroutines you’re coding. You can skim
through this section to understand what the testers are doing. A sample output of our tester is
provided below. Do NOT modify any lines beyond the start of the main section. Doing so can
break our code.
Except for the labels to call the helper subroutines, DO NOT USE ANY OF THE OTHER LABELS
in our code’s main section.
Do not change the tester code in the main section to do additional tests. Additional tests can
be done by editing the simulator’s register and memory values instead of changing our tester
2022/12/12 20:14 Project 4
https://canvas.wisc.edu/courses/323092/assignments/1750056?return_to=https%3A%2F%2Fcanvas.wisc.edu%2Fcalendar%23view_name%3Dmonth%26view_… 3/4
If you’ve successfully implemented all three subroutines, our testers will display the output below. If
you see the message “Check for callee saving failed” as part of the tester outputs, then one or more
registers are not being correctly preserved.
32 * 3 + 1 = 97
196 / 2 = 98
Steps for reaching 1 from 1982 = 99
Number of Collatz Steps for 15, 14, 13, … 3, 2, 1 :
Grading and Submission
(4 pts) The program has good commenting and a good coding style.
(7 pts) The MUL3ADD1 subroutine is successfully completed.
(11 pts) The DIVIDEBY2 subroutine is successfully completed.
(11 pts) The COLLATZ_STEPS subroutine is successfully completed.
For your work to be considered for a grade, you must complete the header comment as
Enter your name, your partner’s name (if working in a pair), and the current date.
Certify the code modifications are your own authorship.
Mark the subroutines you’ve successfully completed.
We will test your program for only the subroutines that you’ve marked in the header comment and
are completed in order. Subroutines that are completed out of order won’t be tested. For example,
if you indicate you’ve only completed COLLATZ_STEPS, then it will be impossible for us to test
your program since testing requires the other two subroutines to also be completed.
Submitting subroutines that don’t work will result in no credit for them.
Save a backup copy of your working program after successfully completing each
subroutine. That way, if you fail to finish the next subroutine, you can submit the copy of your
saved program with the subroutine(s) that you got to work correctly. Make sure to enter the date
and mark the subroutine(s) that were completed so you can distinguish your versions.
When you’re ready, upload your modified program template file containing your LC-3 assembly
language code. Name your file “p4submit.txt”. Canvas will only accept an ASCII text file with a “.txt”
2022/12/12 20:14 Project 4
https://canvas.wisc.edu/courses/323092/assignments/1750056?return_to=https%3A%2F%2Fcanvas.wisc.edu%2Fcalendar%23view_name%3Dmonth%26view_… 4/4
extension. Double check that the file upload to Canvas was successful and it contains the
version of your code you wish to submit. You will receive credit for only the file that you
submit through Canvas.
WORKING INDIVIDUALLY: Upload into Canvas your p4submit.txt file having your modified
WORKING IN A PAIR: ONE PARTNER – Upload into Canvas your p4submit.txt file having your
modified template. BOTH PARTNERS – Fill in and submit a “partner.txt
(https://canvas.wisc.edu/courses/323092/files/28047444?wrap=1)
(https://canvas.wisc.edu/courses/323092/files/28047444/download?download_frd=1) ” file so we can
determine who your partner is. In this text file, you’ll identify which partner will be responsible for
submitting the pair’s work on Canvas for grading. The other partner should not submit your pair’s
https://canvas.wisc.edu/courses/323092/files/28047444?wrap=1
https://canvas.wisc.edu/courses/323092/files/28047444/download?download_frd=1
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com