This lab has you convert a C program that performs 16/32-bit signed operations into PIC24 assembly language.
Download the ZIP archive which contains the lab files. It is located in Canvas > Files > Labs F2024 > Lab 4, and is called lab4.zip. Extract it directly into C:\ece3724. You should now have a folder called C:\ece3724\lab4.
Inside this folder, there are three different exercises, called case4, case5, and case6. You only need to complete one of these.
If you are in lab section...
07 or 05, then you will be doing case4.
03 or 06, then you will be doing case5.
04, then you will be doing case6.
Be sure you do the correct case, or you won't get credit for the lab.
Just like Lab 3, for each case, there's a folder containing MPLAB files, an assembly file for you to complete (case#.s), and a C file (case#_check.c) which contains the C code you'll be translating and also automatically checks your results.
Read Part 2 of the PIC24 Assembly Primer. It contains all the assembly you will need for this lab, and has a Quick Reference on top.
Run your case to make sure it compiles and you can see your UART window. If you are having a problem with MPLAB and can't run your case project, it is your responsibility to contact a TA and get it resolved before coming to lab. Otherwise, you will not get your prelab points.
Complete the program header with your name, date, and section number.
There are three parts of the program labeled PRELAB that you must complete in order to get one PASS. These are the same things you did last week:
Declare your variables
Initialize your variables:
Move your variables into registers so that the C check function can test them.
If you don't have a PASS, or the program now has errors:
Check your code from last week to see where you went wrong.
Check that you're doing mov.b for 8-bit variables and using WREG properly.
Check that you're using .space 4 for the 32-bit variables.
Check that you're using the right numbers and don't have a typo.
Check that you're moving 32-bit values into variables properly:
;; int32_t i32_a = 0x12345678;
mov #0x5678, W0
mov #0x1234, W1
mov W0, _i32_a
mov W1, _i32_a+2
Check that you're moving 32-bit variables into registers properly:
; W1:W0 = i32_a
mov _i32_a, W0
mov _i32_a+2, W1
Check that you moved _u8_e into its register (W7) first, so you don't overwrite what's in W0.
If you still can't get any passes, it's your responsibility to contact a TA for help before coming to lab.
Your program gets at least one PASS. (20)
Your task, once again, is to convert this C program to PIC24 assembly language and get 100 (0x63) passes.
You have to use register assignments. This is a requirement of the lab.
You have to sort your code into Input/Process/Output. This is a requirement of the lab.
You have to move the variables into registers during the Input phase. You have to move the registers to variables (or branch) during the Output phase. This is a requirement of the lab.
You can add extra comments if it helps you keep things straight, but they are not required.
It doesn't matter whether you sign-extend during "Input" or "Process".
If you do not have register assignments and/or are making a big mess of your code, the TA will not help you debug it.
Run your code after writing each fragment. Don't worry about if it passes or not, just make sure it runs. Do not write your entire program and then discover that you have a syntax error but don't know where you went wrong.
You may not ‘optimize’ away any statements – you are to implement the code exactly as shown.
For every code fragment, move the variables into registers during the Input phase. Do not count on values you need still being in registers from some previous part of the code!
Do not use registers W8-15. Use only registers W0-W7.
You must use the proper variable names. The variable names reflect their types: The int32_t variables are signed 32-bit values, int16_t variables are signed 16-bit variables, and uint8_t variables are unsigned 8-bit variables.
When you get all passes, take a screenshot of the final few lines of the simulator output.
You have 100 passes.
You do not need to take a Watches window screenshot for this lab like you did for Lab 3.
See Lab Policy Summary for formatting guidance and a sample report.
The title page should contain the following: Lab name & number, your name & NetID, and course & lab section on successive lines.
Second page should begin with a brief description of the overall lab activity, intelligible to an outside reader. Write a few sentences about what you did in the lab so that an outside reader could understand, e.g. "I translated the following C code into PIC24 assembly..." not "I did case4.s"
Copy/paste the C code you translated (using a monospace font like Courier New) or include a screenshot of it in the report. Do not include your assembly code in the report.
Include the screenshot of your UART window. Write a few sentences about what the reader is supposed to be looking at.
Look over your report and be sure:
It has a neat, professional appearance (Legible screenshots, no blank pages, spelled your name right, etc).
It includes the aforementioned text.
It includes the required 1-2 screenshots, but not extraneous ones (like screenshots of your entire case#.s file, or all 100 PASSes).
Check that your code:
Has the heading filled out with your name and etc.
Has (correct) register assigments.
Has one blank line between code fragments, but no big gaps.
Is indented reasonably.
Uses the Input, Process, Output method correctly.
Does not have any ;Replace this line with your register assigments.
Still gets 100 passes - if you submit non-working code, expect a penalty of up to 60 points.
PDF file with report, including title page, screenshot(s), and appropriate text.
Formatted case#.s file with header and comments.
If you do not successfully complete a task and your report fails to mention or glosses over this fact, you will receive a zero for the report portion of your grade as well as for the task. If you attempt to deceive the grader, e.g. by including screenshots not generated by the code you submitted, your instructor will be notified and you will be recommended for an Honor Code violation.
The report is worth 20 points for neatly and coherently presenting your information to a reader. The following non-exhaustive list of errors will result in losing credit from the report portion of the lab grade:
bad screenshots (not cropped properly, blurry, too small)
text is "lab jargon" unintelligible to an outside reader ("I did case5 and got 100 passes.")
text is phrased as instructions to a second party ("Translate C to Assembly!")
text is copy-pasted from the lab directions rather than using your own words.
text is a literal recap of the activities you performed rather than communicating your results and understanding ("First, I put in register assignments. Then I initialized my variables. Then I set a breakpoint at line 127, in order to see where I was branching wrong..."
blatantly erroneous text ("I wrote the following C code...")
garbled / confusing / gibberish text ("I got 100 debugs whirch runs.")
using vague or incorrect terminology ("The memory byte u32_a increpents each initiation ")
excessive text ("Well, this lab was certainly more difficult than Lab 3. It contained 3x32-bit variables, one 16-bit one, and one that was only 8 bits, which was similarly named (u8_e). The variables had different values than in the last lab. My favorite variable...")
careless use of pagebreaks that leave blank pages, 1-2 lines of text on a page, writing a header on one page and the text all on the following page, etc.
general unprofessional appearance
code is untidy (blank lines, indentations done by RNG)
code is missing header, has wrong header, and/or contains default header
The task is worth 60 points. If your report indicates that you did not successfully complete or do not understand a task, you will lose credit, even if you performed it during the lab. There is one task. The following non-exhaustive list of errors will result in losing credit from the task:
missing screenshot
screenshot of the wrong thing
screenshots show wrong values
cannot read screenshot
code won't run
code performs incorrectly
code passes, but contains mistakes
code doesn't follow lab directions - no/missing/wrong register assignments, no/missing/wrong C code, etc.
Lab reports that flagrantly violate submission policy (wrong lab, no screenshots, no title page, no text besides headings/labels, mostly blank, assembly code pasted into pdf, paragraphs of lab text pasted in, extremely sloppy/unprofessional, missing code etc.) will not be accepted. You will receive a zero for the lab and may resubmit with late penalty.