Lab01 CTEN415
Lab01 CTEN415
Faculty of Engineering
Electrical, Computer and Telecommunications Department
LAB 01
MPLAB X Introduction
The first part of the lab writeup is an introduction to the MPLAB X environment. This has
you demonstrate to the TA that you can use MPLAB X to assemble and simulate an
assembly language program. Demonstrate the following to the TA:
Open the watch window then add u16_i, u16_j, u16_k, and WREG0, WREG1, WREG2.
Use the simulator to single step the program. Watch both the memory locations and
watch window locations, and correlate their changing values with the instructions being
executed.
Reporting Requirement 1
Modify the i = 2047 assignment to be the last four digits of your student ID (the one
on your student ID card decimal numbers do not start with a 0). Reassemble the
program, and re-simulate it. Take a screen shot after running the program of both the
Watch window contents and the data memory (file registers) window contents. In your
report, you must show calculations that verify the screen shot values match the
expected result (warning, i = 2047 is in decimal, as is the last four digits of your
student ID; the values in the screenshot are in HEX). In your report, make it easy for the
TA to see that you have verified the screen values – show your calculations!
Task 2: myadd.s
Create a copy of the mptst_word project:
1. Right-click on the mptst_word project in the Projects window and select Copy...,
then enter myadd as the project name.
3. In the Projects window, under myadd > Source Files, right click on mptst_word.s
and select Remove from project. Now, right-click on Source Files and choose Add
existing item..., then select myadd.s (which is one directory up from the default
location in the project subdirectory).
The following C code describes our program. You must translate each line of the C
program to assembly instruction(s). You MUST include, in comments, a register
assignment followed by one line of C code, followed by your translation to
assembly.
uint16_t u16_lsp;
uint16_t u16_msp;
uint16_t u16_sum;
u16_lsp = 0xY3Y2Y1Y0; // Note that this is a hex value
u16_msp = 0xY7Y6Y5Y4; // Same as above
u16_sum = u16_lsp + u16_msp;
Section 3 of programming reference manual document contains the instruction set of
PIC24.
Use the watch window to watch variables u16_lsp, u16_msp, and u16_sum. Also, use
the data memory window to monitor the memory locations corresponding to these
variables. Write your program, simulate it, and verify that you receive the correct
results.
Take a screen shot of both the Watch window contents and the data memory (file
registers) window contents after running your program. In your report, you must show
calculations that verify the screen shot values match the expected result. Also take a
screen shot of your program listing (If you are using MPLABX v2.xx, do Window >
Output > Disassembly Listing File) and attach myadd.s to your lab submission. In your
report, make it easy for the TA to see that you have verified the screen values – show
your calculations!.
uint8_t u8_i;
uint8_t u8_j;
uint8_t u8_k;
uint8_t u8_l;
uint8_t u8_m;
u8_i = Y1Y0;
u8_j = Y3Y2;
u8_k = Y5Y4;
u8_l = u8_i + u8_j;
u8_m = u8_k – u8_l;
Variables u8_i though u8_m are all 8-bit (byte) variables. ALL operations are byte
operations.
Use the watch window to watch variables u8_i though u8_m. Also, use the data
memory window to monitor the memory locations corresponding to these variables.
Write your program, simulate it, and verify that you receive the correct results. (In the
watch window view variables i, j, k, l as 8-bit unsigned decimal and m as 8-bit signed
decimal. If the expected m value in your case is less than -128 the watch window will
display it as positive value due to underflow(8-bit signed number range is -128 to +127)
in that case please mention this in the lab report) .
Reporting Requirement 3
Take a screen shot of both the Watch window contents and the data memory (file
registers) window contents after running your program. In your report, you must show
calculations that verify the screen shot values match the expected result. Attach
mysub.s to your lab submission. In your report, make it easy for the TA to see that
have verified the screen values, show your calculations!
Report
Your report should have the reporting requirements needed for Tasks 1, 2, and 3.The
TA will take off a significant number of points (20 marks, a zero for the lab report)
if your assembly language source does not have the required comments. The
comments should indicate which assembly language source lines implement which C
statements and give a register assignment for each line of C.
Notes
Do not use the variable names a or b - they are reserved names for the 40 bit
accumulators used by DSP instructions. Using them will give errors during assembly.
If you have confusion on the usage of WREG and W0, refer to programming reference
manual section 3 for the instruction set of PIC24.