Submission Guidelines:
- Every submission must have a coversheet (hardcopy or softcopy) - the coversheet must include your name, semester, date, course number, assignment number, title of the assignment. Use Font 18 and above.
- Evey snapshot/figure must have a description. You will not receive any grade if you do not have a clear description for the snapshot/figure.
- Make sure you include the entire question. If you don't have the entire question you do not receive a grade.
- Each question must be answered by a complete sentence. Example: just writing "22" will not be a complete answer! You should state: The value of register 0x8 will be 0x22"
- Everything must be typed.
- If the scanned figure is not readable, you will not receive a grade.
- Problem statement must be clear and free of any error. Do not just copy the question.; use your own words. Example: "The purpose of this assignment is to design..."
- Your code must have the correct heading - see example file.
LAB 2 (use Assembly language only!) - See submission guidelines above!
A (50 points) - Using MPLABX write instructions for a PIC18F45K20 to store two unsigned 8-bit HEX numbers (e.g., 0x48 and 0x4F) in data registers 0x220 and 0x221, respectively. Add the two numbers and save the sum in register 0x230 and 0x231 (register 0x231 will hold the carry bit - the MSB). Your code should work for any two input values. All values are only expressed in HEX. When the instructions are completed the program should stop by entering into a "continuous loop". You must start your code from location 0x20. See the example file. Submit the following:
- Problem statement as shown above. (5 points)
- Take a snapshot of the first two pages of your code - you must show your program header/version/authors etc. appropriate comments - codes without comments will not receive grade. Your code must include proper format as described in class (5 points).
- Show the contents of registers 0x220, 0x221, 0x230, and 0x231. Use a snapshot. (5 points)
- Answer to the following questions: (10 points).
- How long did it take to complete your code? Explain why. Make sure your instruction frequency (Fcyc) is set to 1 MHz. [does it work?]
- What is your program checksum? Take a snapshot of your project Dashboard.
- What percentage of the FLASH was used for this program? Take a snapshot of your project Dashboard.
- Make sure you test your program using many different values to ensure it works properly! (25 points)
- In your code you must have two registers referring to INPUT1 and INPUT2. These values are your inputs and can be changed by the user.
INPUT1 & 2: |
SUM/Carry: |
Fcyc: |
0x220 |
0x221 |
0x230 |
0x231 |
Time to complete |
|
|
|
|
|
B (50 points) - Using MPLABX write instructions to store two unsigned 8-bit HEX numbers (e.g., 0xF8 and 0x4F) in data registers 0x20 and 0x21, respectively. Your code should figure out which input is larger and subtract the larger from smaller input (e.g., smaller_number - larger_number). The final result must be displayed at PORTC and saved in register 0x30. Note that you already learned how to set PORTC in previous exercises (Appendix F of textbook).You must start your code from location 0x20. Submit the following:
- Problem statement as shown above. (5 points).
- Take a snapshot of the first two pages of your code - you must show your program header/version/authors etc. appropriate comments - codes without comments will not receive grade. Your code must include proper format as described in class (5 points).
- Flowchart of your program. (10 points).
- Show the contents of registers 0x20, 0x21, 0x30, and 0x31. Use a snapshot. (5 points)
- Answer to the following questions: (5 points).
- How long did it take to complete your code? Explain why. Make sure your instruction frequency (Fcyc) is set to 1 MHz. [does it work?]
- What is your program checksum? Take a snapshot of your project Dashboard.
- Make sure you test your program using many different values to ensure it works properly! (25 points)
- In your code you must have two registers referring to INPUT1 and INPUT2. These values are your inputs and can be changed by the user.
INPUT1 & 2 |
Outputs: |
Fcyc: |
0x20 |
0x21 |
0x30 |
PORTC |
Time to complete |
|
|
|
|
|
______________________________
LAB 3 (use Assembly language only!): - See submission guidelines above!
A- In this problem you are designing a simple 8-bit calculator. You must first learn about Test and Skip Operations, branch commands, as well as MULLW and MULWF commands. You must use MPLABX and PIC18F45K20, with Fcyc = 1MHz.
Problem: Assume two non-zero unsigned input values are stored in INPUT1 (reg 0x20) and INPUT2 (reg 0x21) data registers. The result must always be stored in the RESULT (reg 0x40) register. All values are only expressed in HEX. When the instructions are completed the program should go to halt (continuous loop). You must start your code from location 0x20. In your code you must have two variables referring to INPUT1 and INPUT2. These values are your inputs and can be changed by the user at the beginning of the program.
Your calculator must perform FOUR operations: addition, multiplication, division, and subtraction. The nature of the operation can be determined by setting the following bits in the OPERATION (reg 0x30) register:
- If bit_1 & bit_0=01 that means ADDITION operation must be performed (assume the sum is always smaller than 255).
- If bit_1 & bit_0=00 SUBTRACTION operation must be performed. Your code should figure out which input is larger and subtract the larger from smaller input (e.g., smaller_number - larger_number).
- If bit_1 & bit_0=10 MULTIPLICATION operation must be performed (assume the result is always smaller than 255).
- If bit_1 & bit_0=11 DIVISION operation must be performed. Note that the remainder (REM) must be placed in register 0x41.
- If bit_2 is set NO operation must be performed and the RESULTand REM registers must be both cleared.
Submit the following:
- Problem statement as shown above. (5 points).
- Take a snapshot of the first two pages of your code - you must show your program header/version/authors etc. appropriate comments - codes without comments will not receive grade. Your code must include proper format as described in class (5 points).
- Flowchart of your program. (10 points).
- Show the contents of registers as shown in the table below for 8 different test values (two test cases for each operation). Make sure the NOP case works properly. In your code you must have two variables referring to INPUT1 and INPUT2. These values are your inputs and can be changed by the user. (20 points).
- Test the following inputs, assume all inputs are in decimal. Record the outputs for each case, including the number of cycles required to complete the program. Tabulate your results. All results must in HEX. Don't forget the remainder!
|
|
|
12 |
PLUS |
230 |
0 |
PLUS |
255 |
23 |
NEG |
11 |
230 |
NEG |
245 |
54 |
NEG |
123 |
45 |
NEG |
8 |
12 |
MUL |
12 |
0 |
MUL |
18 |
240 |
MUL |
1 |
19 |
MUL |
10 |
17 |
DIV |
3 |
16 |
DIV |
4 |
241 |
DIV |
4 |
0 |
DIV |
12 |
- Assuming your INPUTS are 0x12 and 0x4 with bit_1 & bit_0 = 11, indicating DIVISION operation, using the Logic Analyzer, show the output. Assume the final output is mapped on PORTD (note that PORTD must not change until the final result has been obtained). You may want to zoom in to show that PORTD actually changes. Take a snapshot of your Logic Analyzer. (10 points).
- If your program does not function properly you receive negative 40 points.
Inputs to the program |
Outputs |
Fcyc (number of Cycles required) |
0x20 (INPUT1) |
0x21(INPUT2) |
0x30 (OPERATION) |
0x40 (RESULT) |
0x41 (REM) |
|
|
|
|
|
|
|
___________________________
LAB 4 (use Assembly language only!): - See submission guidelines above!
A- In this problem you are designing a calculator to calculate the MIN. MAX, and AVG values among several given number. Assume the given numbers are located in RAM registers starting with REG20 to REG30. Assume all input values are 8-bit unsigned numbers grater than zero. Complete the following codes:
- Write a program that reads the content of registers REG20 to REG30. A zero register indicates the last input value. The number of non-zero entries must be recorded in a register called NUM_REG (REG40).
- Calculate the average value of the inputs. The average must be recorded in REG41 and called AVG_REG. Assume the sum of all inputs is always divisible by the number of inputs (e.g., the average is always a whole number).
- Find the smallest input value. The smallest number must be recorded in REG42 and called MIN_REG.
- Find the largest input value. The largest number must be recorded in REG43 and called MAX_REG.
Submit the following:
- Problem statement as shown above.
- A complete flow chart of your program (must be done with computer).
- Take a snapshot of your code - you must have appropriate comments - codes without comments will not receive grade. Your code must include proper format as described in class.
- Make sure you test your program using many different values to ensure it works properly!
- Download this file to test your values (change to .xlsx extension). Show your outputs for the given values using appropriate snapshots
_______________
For Later Only
Part IV:
See PART IV or the problem description.
---------------------------------------------------------------------
Later:
a- Write instructions to store two 8-bit HEX numbers (e.g., 0x48 and 0x4F) in data registers 0x20 and 0x21, respectively. Add the two numbers and save the sum in register 0x30. Your code should work for any two values. Identify which flags will be set after the addition. Note: you must start your code from location 0x30. Indicate the value of Registers WREG, 0x20,0x21, 0x30,0x31, and STATUS. Take a snapshot of your code. Your code must include proper format as described in class. For Extra Credit Only: The result must also be shown on the 7-Segment screen.
b- Write instructions to load two numbers from registers 0x30 and 0x31 (say, numbers 0x7F and 0x28) and subtract the larger from the smaller. Your code must figure out which number is larger and which is smaller. Display the results at PORTC and also save it in register 0x30. Identify which flags will be set after the addition. Indicate the value of Registers WREG, PORTC, 0x30,0x31, and STATUS. Note: you must start your code from location 0x40. Take a snapshot of your code. Your code must include proper format as described in class. Must do the flowchart first!
Part II:
Make sure you test your program using many different values to ensure it works properly! Before doing these problems make sure you have carefully read chapter 4 (and all other related materials provided on the web) and completed Simulation exercises on page 121.
Write a program to add any unsigned 24-bit numbers stored in the following registers: NUM1L (lowest byte), NUM1H (middle byte), NUM1U (highest byte), NUM2L (lowest byte), NUM2H (middle byte), NUM2U (highest byte). The number must be stored in SUML (lowest byte), SUMH (middle byte), SUMU (highest byte), and CARRY_BIT. If the carry bit is set all three SUM registers must be cleared. Otherwise, the SUM register must reflect the correct result. Note that RC1 (bit 1 of PORTD) must reflect the status of the CARRY_BIT. You must submit the following: flowchart for your code and a snapshot of the results and code. You need to demonstrate to the instructor that the program operates properly. (50 points) - Must do the flowchart first!
Test: Check the following: NUM1 NUM2 SUM CARRY_BIT(RC1)
Test 1 /
Input |
Results |
Remainder |
(solution is here!)